我一次 取10个 项目的数据 dim aa(10) as intfor i=0 to 9 aa(i)=i select * from table1 where id=aa(i) insert into table2 next ....... 这段代码 怎样用存储过程实现?
SQL不支持数组及for循环.数组可以用表变量,临时表代替.for循环可以用while代替
--对于楼主的,可以改为:declare @t table(id int identity(1,1),aa int) insert into @t select * from table1 where id between 0 and 9
--如果严格按楼主的,写成循环:declare @t table(id int identity(1,1),aa int)declare @i int set @i=0while @i<=9 begin insert into @t(aa0 values(@i) select * from table1 a join @t b on a.id=b.aa where b.id=@i --insert into table2 --不知道楼主这句是什么意思? end
--上面的我少写了一个赋值的declare @t table(id int identity(1,1),aa int)declare @i int set @i=0while @i<=9 begin insert into @t(aa0 values(@i) select * from table1 a join @t b on a.id=b.aa where b.id=@i set @i=@i+1 --insert into table2 --不知道楼主这句是什么意思? end
dim aa(10) as intfor i=0 to 9
aa(i)=i
select * from table1 where id=aa(i)
insert into table2
next
.......
这段代码 怎样用存储过程实现?
insert into @t select * from table1 where id between 0 and 9
set @i=0while @i<=9
begin
insert into @t(aa0 values(@i)
select * from table1 a join @t b on a.id=b.aa
where b.id=@i
--insert into table2 --不知道楼主这句是什么意思?
end
set @i=0while @i<=9
begin
insert into @t(aa0 values(@i)
select * from table1 a join @t b on a.id=b.aa
where b.id=@i
set @i=@i+1
--insert into table2 --不知道楼主这句是什么意思?
end