bulk insert txt error with ROWTERMINATOR

天涯浪子 提交于 2020-01-03 02:39:06

问题


Have a txt file and have to pass it to sql

A bulk insert

BULK INSERT table
FROM '\ \ 01cends5 \ TestBulk \ a.txt'
WITH (
DATAFILETYPE = 'char'
FIELDTERMINATOR = '|'
ROWTERMINATOR = '\ n ',
FIRSTROW = 1,
LASTROW = 15
)

But it do not take as a final line ROWTERMINATOR and probe everything and does not work
{CR} {LF}{LF}{CR}\ n\ r\ r \ n\ n \ r

My txt format is:

0 | 20276708598 | 119302 | 201101 | 000000 | 000000


回答1:


It looks like something is wrong with '\r' translation to 0x0A, at least in my case.

http://dbaspot.com/sqlserver-programming/463913-bulk-insert-rowterminator-failing.html#post1509360 demonstrates how to do it with exec and specifying of rowterminator with char() function. It worked for me. Paste of sample code from the link above:

DECLARE @bulk_cmd varchar(1000)
SET @bulk_cmd = 'BULK INSERT [GRC].[dbo].[UP_040109]
FROM ''C:\TEMP\up\524.d.0''
WITH (ROWTERMINATOR = '''+CHAR(10)+''',FIELDTERMINATOR = ''\t'')'
EXEC(@bulk_cmd)


来源:https://stackoverflow.com/questions/5818440/bulk-insert-txt-error-with-rowterminator

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!