先导入一个临时表tmp,同时增加一自增列id,数据列为col,然后对应取值后插入你需要的表.--查询
select
max(case (id-1)%3 when 0 then col else '' end) A,
max(case (id-1)%3 when 1 then col else '' end) B,
max(case (id-1)%3 when 2 then col else '' end) C
from tmp
group by (id-1)/3--插入结果表TB
insert into tb
select
max(case (id-1)%3 when 0 then col else '' end) A,
max(case (id-1)%3 when 1 then col else '' end) B,
max(case (id-1)%3 when 2 then col else '' end) C
from tmp
group by (id-1)/3
select
max(case (id-1)%3 when 0 then col else '' end) A,
max(case (id-1)%3 when 1 then col else '' end) B,
max(case (id-1)%3 when 2 then col else '' end) C
from tmp
group by (id-1)/3--插入结果表TB
insert into tb
select
max(case (id-1)%3 when 0 then col else '' end) A,
max(case (id-1)%3 when 1 then col else '' end) B,
max(case (id-1)%3 when 2 then col else '' end) C
from tmp
group by (id-1)/3
--例:有表os
create table os(a varchar(10),b varchar(10),c varchar(10))
--将文本文档导入os表中--先创建临时表:
create table #(val varchar(10))--将文本文档导入临时表:
BULK INSERT #
FROM 'd:\c.txt'
WITH (
ROWTERMINATOR = '\n' --行以换行符隔开
)--将临时表中数据导入表中。
insert into os
select a.val,b.val,c.val from # a,# b,# c where
left(a.val,1)='A' and left(b.val,1)='B' and left(c.val,1)='C'
and replace(a.val,'A','')=replace(b.val,'B','')
and replace(a.val,'A','')=replace(c.val,'C','') --查看结果
select * from os
在帮助中查查cmdshell的用法,就可以了