我在批量插入包含数据类型文本字段的文件时遇到问题,它包含输入,字段的分隔符是管道“|” 并且行终止符是“|\n”
我收到文本字段旁边的字段截断错误。我认为批量插入认为第二个字段中的输入是下一行。
DECLARE @sql varchar(2000)
PRINT 'xyz table'
SET @sql =
'BULK INSERT xyz
FROM ''\\' + @@servername + '\Import\xyz.txt''
WITH
(
DATAFILETYPE = ''char'',
FIELDTERMINATOR = ''|'',
ROWTERMINATOR = ''|\n'',
TABLOCK,
ROWS_PER_BATCH = 2000,
MAXERRORS = 1000
)
'
PRINT @sql
EXECUTE (@sql)
PRINT ''
GO
这是数据示例
467507**|**08-20-09\
[8:55:03 AM] *** miked@wkaiser-6793 is Not Available [Ext. away]\(CR)
[9:00:57 AM] *** miked@wkaiser-6793 is Online [Online]\(CR)
[9:01:00 AM] <jeffp> Howdy. Time slip update game! Update TS#467493 & 467507 with a (CR)comment and see if you win! [9:01:30 AM] *** miked@wkaiser-6793 is Away [Away]\
\(CR)
08-18-09\(CR)
[10:13:15 AM] *** miked@wkaiser-6793 is Online [Online]\(CR)
[10:13:59 AM] <jeffp> Howdy; welcome back from lunch.. Just pinging you for an update in TS#467493 & 467507. Since 467493 is pri9, want a stock e-mail to go out to the customer to get them moving?\(CR)
[10:14:47 AM] <miked@wkaiser-6793> thats ok i got it\(CR)
[10:14:53 AM] <jeffp> Aiight.**|**2009-08-18 00:00:00**|**2009-08-20 00:00:00**|**JDP**|**JDP**|**
表架构是:
create table xyz
(
xyz_id VARCHAR(200), --INT TO VARCHAR
notes text,
create_date varchar(32), --DATETIME
create_user varchar(12),
modify_date varchar(32), --DATETIME
modify_user varchar(12)
)
如您所见(好吧,看不到),有输入(用 CR 标记)并且批量插入将它们与新行混淆。
任何帮助将不胜感激。
谢谢