Search code examples
csvsql-server-2005windows-server-2008sqlcmd

SQLCMD to csv - trailing spaces differs between Windows versions


I use this command for exporting data from SQL Server 2005 to .csv:

sqlcmd -S (local)\DB -i  c:\Temp\sqlexport\query_trans.sql -o c:\Temp\sqlexport\transactions.csv -W -s ";"

which produces the .csv file.

The problem I've encountered is that while on Windows 7 this works perfectly, Windows 10 and Windows Server 2008 produce a large amount of trailing spaces in some columns.

How can that functionality differ between Windows versions, and how can I solve it? I already have the -W option as you can see.

Thanks for any suggestions.


Solution

  • I had to use a workaround in my SELECT statement

    SELECT
    LTRIM(RTRIM(COLUMNNAME))
    

    to make it work. It would be interesting if someone knew why different windows doesn't trim whitespaces in the csv with -W option