批量插入后特殊字符显示不正确 [英] Special characters displaying incorrectly after BULK INSERT
问题描述
我正在使用批量插入
导入CSV文件。 CSV文件中的一列包含一些包含分数的值(例如1m½f
)。
I'm using BULK INSERT
to import a CSV file. One of the columns in the CSV file contains some values that contain fractions (e.g. 1m½f
).
我不需要对分数进行任何数学运算,因为这些值仅用于显示目的,因此我将列设置为 nvarchar
。 大容量插入
可以工作,但是当我查看SQL中的记录时,分数已被替换为美分符号(¢
)所以显示的文字是 1m¢f
。
I don't need to do any mathematical operations on the fractions, as the values will just be used for display purposes, so I have set the column as nvarchar
. The BULK INSERT
works but when I view the records within SQL the fraction has been replaced with a cent symbol (¢
) so the displayed text is 1m¢f
.
我有兴趣了解为什么会这样以及有什么想法有关如何解决此问题的信息。 大容量插入
命令为:
I'm interested to understand why this is happening and any thoughts on how to resolve the issue. The BULK INSERT
command is:
BULK INSERT dbo.temp FROM 'C:\Temp\file.csv'
WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' );
推荐答案
您需要大容量插入
使用 CODEPAGE ='ACP'
,它将字符串数据从Windows代码页1252转换为SQL Server代码页。
You need to BULK INSERT
using the CODEPAGE = 'ACP'
, which converts string data from Windows codepage 1252 to SQL Server codepage.
BULK INSERT dbo.temp FROM 'C:\Temp\file.csv'
WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '\n', CODEPAGE = 'ACP');
如果要在足够新版本的SQL Server上引入UTF-8数据:
If you are bringing in UTF-8 data on a new enough version of SQL Server:
[...] , CODEPAGE = '65001');
您可能还需要指定 DATAFILETYPE ='char | native | widechar |扩展'
。
这篇关于批量插入后特殊字符显示不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!