问题
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