批量插入表中的多个管道数据

时间:2012-09-07 12:11:30

标签: sql sql-server

我写了一个查询,将.lst文件中的数据插入到表名AxisATM中但是当我尝试插入它时给出了错误

当我从LST文件中删除所有行时除了First ..它给了我成功消息说1行改变了..

Msg 4866, Level 16, State 1, Line 1
The bulk load failed. The column is too long in the data file for row 1, column 36. Verify that the field terminator and row terminator are specified correctly.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".

查询: -

    BULK
INSERT dbo.ATMAxis
FROM 'c:\AGS_WINCORE_120901.lst'
WITH
(
FIELDTERMINATOR = '|',
ROWTERMINATOR = 'CHAR(13)'
)
GO

AGS_WINCORE_120901.lst: -

PRO1|......|00000000000|0| {Like it has 36 '|' separators}

使用Notepad ++我知道行结束字符是CR LF

3 个答案:

答案 0 :(得分:2)

正如所料,问题在于

ROWTERMINATOR = 'CHAR(13)'

我已将其更改为

ROWTERMINATOR = '0x0A'

答案 1 :(得分:0)

正如错误所示,第36列的表格多于表格列第36列。您需要增加该列的大小

答案 2 :(得分:0)

似乎行终止符会产生问题。如果是这种情况,请尝试将/r/n替换为Char(10),这样可以解决问题。另外,请检查char(13)

This MSDN thread有更多信息。