How can i put the result of a sql server query into a "comma delimited" format?
如何将sql server查询的结果变为“逗号分隔”格式?
4 个解决方案
#1
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.
您应该能够转到SQL Server Management Studio中的工具 - >选项 - >查询结果,并在那里设置首选项以输出到文本文件。
Then expand that and in "Result to Text" you can set the output format there.
然后展开它,在“结果到文本”中,您可以在那里设置输出格式。
#2
Check out this answer on the MySQL forums.
在MySQL论坛上查看这个答案。
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;
#3
If you are using sql server managment studio right click on the output and you can "Save Result as" CSV
如果您正在使用sql server管理工作室右键单击输出,您可以“将结果另存为”CSV
#4
DECLARE @str VARCHAR(8000) SET @str = ''
DECLARE @str VARCHAR(8000)SET @str =''
SELECT @str = @str + column + ',' FROM table SELECT @str
SELECT @str = @str + column +','FROM table SELECT @str
#1
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.
您应该能够转到SQL Server Management Studio中的工具 - >选项 - >查询结果,并在那里设置首选项以输出到文本文件。
Then expand that and in "Result to Text" you can set the output format there.
然后展开它,在“结果到文本”中,您可以在那里设置输出格式。
#2
Check out this answer on the MySQL forums.
在MySQL论坛上查看这个答案。
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;
#3
If you are using sql server managment studio right click on the output and you can "Save Result as" CSV
如果您正在使用sql server管理工作室右键单击输出,您可以“将结果另存为”CSV
#4
DECLARE @str VARCHAR(8000) SET @str = ''
DECLARE @str VARCHAR(8000)SET @str =''
SELECT @str = @str + column + ',' FROM table SELECT @str
SELECT @str = @str + column +','FROM table SELECT @str