不能用数组,不能用for循环。可以用游标,while来代替。

解决方案 »

  1.   

    可以用while循环。不过,能写成一句SQL语句的,或是能借助临时表的,就尽量不用循环。
      

  2.   

    我一次 取10个 项目的数据
    dim aa(10) as intfor i=0 to 9
        aa(i)=i
     select * from table1 where id=aa(i)
     insert into table2
     next
    .......
    这段代码 怎样用存储过程实现?
       
      

  3.   

    SQL不支持数组及for循环.数组可以用表变量,临时表代替.for循环可以用while代替
      

  4.   

    --对于楼主的,可以改为:declare @t table(id int identity(1,1),aa int)
    insert into @t select * from table1 where id between 0 and 9
      

  5.   

    --如果严格按楼主的,写成循环: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
      

  6.   

    --上面的我少写了一个赋值的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