Export query result to csv in UTF-8

好久不见. 提交于 2019-12-23 05:40:29

问题


I would like to export query result to csv file in utf-8. Now i export to csv in this way:

    DECLARE @cmd varchar(1000)
    SET @cmd = 'bcp "select * from table" queryout "d:\textfile.csv" -w -T -t; -Slocalhost'
    EXEC xp_cmdshell @cmd

How to make file be in UTF-8?


回答1:


SQL Server does not support code page 65001 (UTF-8 encoding). reference

You need to add -w parameter in bcp utility to specify the encoding is UTF16.




回答2:


I am sure you have long since solved your problem but as this is still open thought it might help someone else.

I am creating txt files with SQL Server queries and they seem to be "plain ANSI". In the end I used iconv.exe to convert from WINDOWS-1252 to UTF-8

iconv.exe is part of the GnuWin package which can be downloaded from Sourceforge https://sourceforge.net/projects/gnuwin32/



来源:https://stackoverflow.com/questions/25707759/export-query-result-to-csv-in-utf-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!