我提个想法,不知道是否有用的说。
我用的是BCB6+TADOQuery。
首先,执行从T1中得到所有的记录。
SELECT * FROM T1
接着,循环读取从T1中得到的记录集dataset,每次5条记录,依次赋值到一个自定义数组temp中。
int temp[5];
for( int i=0; i<总记录数; i=i+5 ) // 一个循环,推出条件是到达记录尾
{
temp[i] = 第i条记录;
temp[i+1] = 第i+1条记录;
temp[i+2] = 第i+1条记录;
temp[i+3] = 第i+1条记录;
temp[i+4] = 第i+1条记录;
SQLCmd = "INSERT INTO T2 (A1, A2, A3, A4, A5) VALUES ("
+ temp[i] + ", "
+ temp[i+1] + ", "
+ temp[i+2] + ", "
+ temp[i+3] + ", "
+ temp[i+4] + ") "; // 根据temp数组中的内容产生SQL命令
执行SQL命令;
}考虑到T2中最后一条记录可能出现有几个字段没有对应的记录可以导入,你可以在赋值的时候加入一些判断,或者使用一个static变量来做控制,总之,关键就是把T1中的记录添加到SQL的insert命令中,最后执行就是了。
我用的是BCB6+TADOQuery。
首先,执行从T1中得到所有的记录。
SELECT * FROM T1
接着,循环读取从T1中得到的记录集dataset,每次5条记录,依次赋值到一个自定义数组temp中。
int temp[5];
for( int i=0; i<总记录数; i=i+5 ) // 一个循环,推出条件是到达记录尾
{
temp[i] = 第i条记录;
temp[i+1] = 第i+1条记录;
temp[i+2] = 第i+1条记录;
temp[i+3] = 第i+1条记录;
temp[i+4] = 第i+1条记录;
SQLCmd = "INSERT INTO T2 (A1, A2, A3, A4, A5) VALUES ("
+ temp[i] + ", "
+ temp[i+1] + ", "
+ temp[i+2] + ", "
+ temp[i+3] + ", "
+ temp[i+4] + ") "; // 根据temp数组中的内容产生SQL命令
执行SQL命令;
}考虑到T2中最后一条记录可能出现有几个字段没有对应的记录可以导入,你可以在赋值的时候加入一些判断,或者使用一个static变量来做控制,总之,关键就是把T1中的记录添加到SQL的insert命令中,最后执行就是了。
select a1=(select fieldA from #t1 where (id mod 5)=1),
a2=(select fieldA from #t1 where (id mod 5)=2),
.......
a5=(select fieldA from #t1 where (id mod 5)=0)
from #t1
insert into #t1 values(1)
insert into #t1 values(2)
insert into #t1 values(3)
insert into #t1 values(4)
insert into #t1 values(5)
insert into #t1 values(6)
insert into #t1 values(7)
insert into #t1 values(8)
insert into #t1 values(9)
select identity(bigint,1,1) as id, * into #t2 from #t1
select id as oldid, (id % 5) as id,a into #t3 from #t2select * from (select a1=(select a from #t3 where id=1 and oldId=s.oldid),
a2=(select a from #t3 where id=2 and oldId=s.oldid+1),
a3=(select a from #t3 where id=3 and oldId=s.oldid+2),
a4=(select a from #t3 where id=4 and oldId=s.oldid+3),
a5=(select a from #t3 where id=0 and oldId=s.oldid+4)
from #t3 s) x where a1 is not null