Reputation: 3629
How can i put the result of a sql server query into a "comma delimited" format?
Upvotes: 1
Views: 16587
Reputation: 1585
DECLARE @str VARCHAR(8000) SET @str = ''
SELECT @str = @str + column + ',' FROM table SELECT @str
Upvotes: -1
Reputation: 1061
If you are using sql server managment studio right click on the output and you can "Save Result as" CSV
Upvotes: 1
Reputation: 8334
You should be able to go to Tools->Options->Query Results
in SQL Server Management Studio and set the preferences there to output to a text file.
Then expand that and in "Result to Text" you can set the output format there.
Upvotes: 4
Reputation: 70031
Check out this answer on the MySQL forums.
Here's the snippet.
SELECT a,b INTO OUTFILE '/tmp/result.text'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM test_table;
Upvotes: 1