title: How can I remove trailing spaces from a SQL Server 2008 query when exporting to csv?
body: <p>Here's the problem.  I run a query in SQL Server Management Studio.  I click "Save results As..." and save the file as CSV.  When I open the CSV file (with Notepad or any text editor), trailing spaces have been added on every column to make them a uniform width.  This is extremely frustrating, because when I open the file with Excel, it auto-converts the fields into columns, changing account numbers and such to scientific notation.</p>
  
  <p>With SQL Server 2005, there are no trailing spaces added, so Excel just puts all the data in a single column.  Then I can convert text to columns and specify every column to be Text.  But my company has switched me to SQL Server 2008 and now the only way to get the correct formatting is to import the CSV into Access, run Trim functions in Access (and thus change the field names) to get rid of the spaces, then export from Access to Excel.  PLEASE HELP!!!  Why the heck is SQL Server 2008 adding trailing spaces and where is the option to make it stop???</p>
  
  <p>SOLVED: Please see my answer below.</p>