1

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?

IComparable
  • 71
  • 1
  • 1
  • 10

2 Answers2

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.

VahidN
  • 18,457
  • 8
  • 73
  • 117
1

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/

ceemjay
  • 23
  • 5