I am trying to use sqlcmd to output the results from a stored procedure to a text file. However, it is putting a space between the resulting columns (a default delimiter) and I need to remove this. I am using the below code and have tried specifying nothing as the column separator see code below (-s "") but this does not work. It gives me a missing argument error.
sqlcmd -S Server name -U Username-P Password -d Db name-Q
"exec Stored procedure" -h -1 -s "" -o c:\newtest.txt
How can I specify nothing as the delimiter?
It can be done with bcp, using -t 0x90
-t is the field terminator in bcp. you can use it on stored procs as well as tables so it should do everything you need.
I just verified this works:
bcp dbname.dbo.tablename out "c:\test.txt" -S serveraddress -U username -P password -t 0x90 -c
Using a stored proc would be something like:
bcp "EXEC YourDatabaseNameGoesHere.dbo.sp_myproc ''0123,0234,0345''"