January 21, 2014 at 7:53 am
are you replacing <SERVERNAME> with your server name right?
Can you please check the syntax try to print the @cmd and check.
January 21, 2014 at 7:56 am
Hi, Sorry yes I am replacing <SERVERNAME>. Thanks
So the cmd looks like -
sqlcmd -S MyServerName -E -h -1 -d AdventureWorks -Q "SET NOCOUNT ON; SELECT U.[UserId] ,U.[UserName] ,U.[DateCreated] FROM dbo.Users U" -o "C:\test_output_file.csv" -s","
January 21, 2014 at 8:34 am
Remove "SET NOCOUNT ON" and try to execute you command
January 22, 2014 at 3:19 am
Hi,
Thanks for your reply. The reason why I added that was to remove the row count on the output of the CSV. However I removed the section as you suggested and the output was with whitespace. See below -
CB8ECBE0-EDEB-41CB-B8B1-B15DC8F1A70E,Temp123 ,2014-01-21 10:03:32.750
66D53C8E-E543-4B55-983C-F0BE97936655,User123 ,2014-01-22 10:03:32.753
(2 rows affected)
January 22, 2014 at 4:52 am
There's a -W parameter to SQLCMD that removes trailing spaces from fields--would that work for you?
January 22, 2014 at 7:27 am
paul.knibbs (1/22/2014)
There's a -W parameter to SQLCMD that removes trailing spaces from fields--would that work for you?
Thanks Paul, Passing the -W parameter did the trick.
Many Thanks
January 24, 2014 at 6:03 pm
Instead of using SQLCMD for this, I'd recommend the use of BCP instead (with the understanding that it won't give you column headers).
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply