CREATE PROCEDURE test
as
declare @aaa int,@bbb int,@ccc intselect @aaa=aaa,@bbb=bbb,@ccc=ccc from test1select @aaa,@bbb,@ccc为什么出来的老是表TEXT1的最后一条记录select @aaa=aaa,@bbb=bbb,@ccc=ccc from test1
查询完比例有4条记录
结束只显示一条,怎么办

解决方案 »

  1.   

    select @aaa,@bbb,@ccc 这就是显示1条,把这句删除
      

  2.   

    可以用游标实现:
    CREATE PROCEDURE test
    as
    declare @aaa int,@bbb int,@ccc intdeclare upcur cursor for select aaa,bbb,ccc from test1open upcur
    fetch next from upcur into @aaa,@bbb,@ccc
    while @@fetch_satus
    beginselect @aaa,@bbb,@cccend
    close upcur
    deallocate upcur
      

  3.   

    CREATE PROCEDURE test
    as
    declare @aaa int,@bbb int,@ccc intdeclare upcur cursor for select aaa,bbb,ccc from test1open upcur
    fetch next from upcur into @aaa,@bbb,@ccc
    while @@fetch_satus
    beginselect @aaa,@bbb,@ccc
    --  不好意思,这里少了一个fetch
    fetch next from upcur into @aaa,@bbb,@cccend
    close upcur
    deallocate upcur
      

  4.   

    sorry ,揭帖继续回答,应该是while @@fetch_status = 0