如何将utf-8数据从sql server 2008导出为excel
我尝试从SQL Server 2008中导出utf-8数据到excel有两个选项。 但是data-utf-8是不正确的
示例我有一个表有Name列(Collation:SQL_Latin1_General_CP1_CI_AS,nvarchar(3000))
|Name | |TrÆ°á»ng ÄH Dược|
如果我使用asp代码在浏览器上显示它
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
数据会显示正确的
|Name | |Trường ĐH Dược |
但是,当我出口到擅长:
选项1我使用
Enable Ad Hoc Distributed Queries EXEC sp_configure 'show advanced options', 1; GO RECONFIGURE; GO EXEC sp_configure 'Ad Hoc Distributed Queries', 1; GO RECONFIGURE; GO INSERT INTO OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 8.0;Database=C:\testing.xls;', 'SELECT Name, Email FROM [Sheet1$]') SELECT Name, Email FROM tblnames GO
或选项2:我使用
SQL Server Import and Export Wizard
但是这两个选项都不显示正确的data-utf-8。 它仍然像
|Name | |TrÆ°á»ng ÄH Dược|
如何从SQL Server 2008导出UTF-8数据,以表示感谢
你可以尝试BCP批量出口,但2008R2
SQL Server不支持代码页65001(UTF-8编码)。 参考
您需要在bcp实用程序中添加-w参数以指定编码为UTF16。
DECLARE @cmd varchar(1000) SET @cmd = 'bcp "select * from table" queryout "d:\file.csv" -w -T -t; -Slocalhost' EXEC xp_cmdshell @cmd
然后尝试在Excel中打开CSV