批量插入空列UCS-2 Little Endian

时间:2013-02-06 14:22:05

标签: tsql sql-server-2008-r2 bulkinsert

我有一个使用批量插入命令导入的制表符分隔文件。 我有一个格式文件如下。

8.0
9
1       SQLCHAR       0       50      "\t"                          1     Field1             "SQL_Latin1_General_CP1_CI_AS"
2       SQLCHAR       0       50      "\t"                          2     Field2             "SQL_Latin1_General_CP1_CI_AS"
3       SQLCHAR       0       50      "\t"                          3     Field3             "SQL_Latin1_General_CP1_CI_AS"
4       SQLCHAR       0       50      "\t"                          4     Field4             "SQL_Latin1_General_CP1_CI_AS"
5       SQLCHAR       0       50      "\t"                          5     Field5             "SQL_Latin1_General_CP1_CI_AS"
6       SQLCHAR       0       50      "\t"                          6     Field6             "SQL_Latin1_General_CP1_CI_AS"
7       SQLCHAR       0       50      "\t"                          7     Field7             "SQL_Latin1_General_CP1_CI_AS"
8       SQLCHAR       0       50      "\t"                          8     Field8             "SQL_Latin1_General_CP1_CI_AS"
9       SQLCHAR       0       0       "\r\n"                        9     Field9              "SQL_Latin1_General_CP1_CI_AS"

哪个适用于ANSI文件,但是我收到的文件是UCS-2 Little Endian编码。

我尝试使其工作的方法是对格式文件使用以下修正。这会阻止任何错误,但我得到所有空列的正确行数。如果可能的话,我想避免转换文件。

8.0
9
1       SQLCHAR       0       50      "\t\0"                          1     Field1             "SQL_Latin1_General_CP1_CI_AS"
2       SQLCHAR       0       50      "\t\0"                          2     Field2             "SQL_Latin1_General_CP1_CI_AS"
3       SQLCHAR       0       50      "\t\0"                          3     Field3             "SQL_Latin1_General_CP1_CI_AS"
4       SQLCHAR       0       50      "\t\0"                          4     Field4             "SQL_Latin1_General_CP1_CI_AS"
5       SQLCHAR       0       50      "\t\0"                          5     Field5             "SQL_Latin1_General_CP1_CI_AS"
6       SQLCHAR       0       50      "\t\0"                          6     Field6             "SQL_Latin1_General_CP1_CI_AS"
7       SQLCHAR       0       50      "\t\0"                          7     Field7             "SQL_Latin1_General_CP1_CI_AS"
8       SQLCHAR       0       50      "\t\0"                          8     Field8             "SQL_Latin1_General_CP1_CI_AS"
9       SQLCHAR       0       0       "\r\0\n\0"                      9     Field9               "SQL_Latin1_General_CP1_CI_AS"

3 个答案:

答案 0 :(得分:2)

你几乎就在那里,只需将SQLCHAR更改为SQLNCHAR

答案 1 :(得分:1)

你的问题帮助我得到了另一个类似问题的答案谢谢

" \吨\ 0"是金! (愚蠢的UNICODE :()

(我已经有了SQLNCHAR SQLNVARCHAR PART :))

答案 2 :(得分:0)

您的BULK INSERT声明是什么样的?您可能需要添加DATAFILETYPE

 BULK INSERT {TableName}
 FROM '{FilePath}'
 WITH (DATAFILETYPE = 'widechar', FORMATFILE = '{FormatFilePath}')