I need to dump my sql query result into the text file. i have created the following query,
DECLARE @cmd VARCHAR(2048)
SET @cmd = 'OSQL -Slocalhost '
+ ' -UCRN370 -PCRN370'
+ ' -Q"SELECT TOP 5 GageId FROM EwQMS370..msgages"'
+ ' -oc:\authors.csv'
EXEC master..xp_cmdshell @cmd, NO_OUTPUT
The above query created the CSV file authors.CSV. But the content of the file is not formatted properly. They showed some junk data.
I need to create a formatted csv file.