using SQLCMD to export/extract data withot trailing spaces I am trying to extract data from some of my tables using sqlcmd utility as SSMS does not generate appropriate csv-s for me.
My issue: all csv extract includes trailing spaces according to table definitions (I mean field length) regardless of using char, varchar, nvarchar, etc...
When using sqlcmd utility eg with following options:
sqlcmd -S . -d /*databasename*/ -E -s, -W -Q &quot;SELECT * FROM /*tablename*/&quot; &gt; C:\Test.csv

it is still contains trailing spaces, eg:
,&quot;273                 &quot;,

any hints or tips to do this in SSMS and/or correcting my parameters for SQLCMD?
Despite how the SQLCMD usage screen (SQLCMD -?) describes the -W parameter:

[-W remove trailing spaces]

the actual purpose of this parameter is not to remove existing trailing spaces but rather to skip padding a value with spaces.  If a string value already has trailing spaces of its own, they cannot be removed if you simply specify the -W parameter.
As far as I can see, there is no way to resolve this issue with parameters.  You will have to either manipulate the output with text processing utilities or generate the values without the trailing spaces in the first place.  For the latter you can use the RTRIM() function, but that, of course, means you will have to replace the SELECT * with an actual column list, where some columns would be computed columns:
SELECT
  ...
  RTRIM(SomeStringColumn) AS SomeStringColumn,
  ...
FROM
  ...