我在使用 2008 和批量插入时遇到问题。我无法让它处理可变长度记录(特别是标题)。
给定以下文件行:
- 1,2,3,4,5,6,7,9,10
- 1,2,3,4,5,6,7,9,10,1,2,3,4,5,6,7,9,10
- 1,2,3,4,5,6,7,9,10,1,2,3,4,5,6,7,9,10
- 1,2,3,4,5,6,7,9,10,1,2,3,4,5,6,7,9,10
- 1,2,3,4,5,6,7,9,10,1,2,3,4,5,6,7,9,10
- 1,2,3,4,5,6,7,9,10,1,2,3,4,5,6,7,9,10
- 1,2,3,4,5,6,7,9,10,1,2,3,4,5,6,7,9,10
- 1,2,3,4,5,6,7,9,10,1,2,3,4,5,6,7,9,10
- 1,2,3,4,5,6,7,9,10,1,2,3,4,5,6,7,9,10
- 1,2,3,4,5,6,7,9,10,1,2,3,4,5,6,7,9,10
以下不应该做一些有用的事情,比如导入数据吗?而不是返回一个空表,或者如果 FirstRow 小于 2 则返回错误?
我不记得导入和 SQL 2000 有这么多问题。
drop table #data
create table #data
(
a int null, b int null
,c int null, d int null
,e int null, f int null
,g int null, h int null
,i int null, j int null
,k int null, l int null
,m int null, n int null
,o int null, p int null
,q int null, r int null
,s int null, t int null
)
truncate table #data
bulk insert #data
from 'd:\temp\data.txt'
WITH(
TABLOCK
,CODEPAGE='RAW'
,DATAFILETYPE='char'
,FIELDTERMINATOR=','
,ROWTERMINATOR='\r\n'
,FIRSTROW=2
)
select * from #data
忘了提一下,我试过 SSIS 但没有区别……显然我可能使用了错误的组件。
哦,我可以在那里得到 99%,批量插入除了第二行之外的所有内容:(但这对任何人都没有用!