tags:

views:

1631

answers:

4

How can i put the result of a sql server query into a "comma delimited" format?

A: 

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;
Ólafur Waage
+1  A: 

If you are using sql server managment studio right click on the output and you can "Save Result as" CSV

Aaron
+3  A: 

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.

Ryan Smith
A: 

DECLARE @str VARCHAR(8000) SET @str = ''

SELECT @str = @str + column + ',' FROM table SELECT @str

JNappi
Really useful if the data itself contains commas.
John Machin