declare @bb int
   DECLARE lsb1 CURSOR FOR 
    select * from zwqd
    if @@rowcount>0
    begin
      set @bb=1
    end
  DEALLOCATE lsb1
select @bb现在@bb=1不起作用~~!游标是必须用的~~不知道怎么写了

解决方案 »

  1.   

    下面的示例用 @@FETCH_STATUS 控制在一个 WHILE 循环中的游标活动。DECLARE Employee_Cursor CURSOR FOR
    SELECT LastName, FirstName FROM Northwind.dbo.Employees
    OPEN Employee_Cursor
    FETCH NEXT FROM Employee_Cursor
    WHILE @@FETCH_STATUS = 0
    BEGIN
       FETCH NEXT FROM Employee_Cursor
    END
    CLOSE Employee_Cursor
    DEALLOCATE Employee_Cursor
      

  2.   

    declare @bb int
       DECLARE lsb1 CURSOR FOR select 1 from zwqd
       open lsb1
       fetch lsb1 into @bb
        while @@fetch_status=0
        begin
          set @bb=1
          fetch lsb1 into @bb
        end
       close lsb1
      DEALLOCATE lsb1
    select @bb 
      

  3.   

    declare @bb int
    set @bb=0
       DECLARE lsb1 CURSOR FOR select 1 from zwqd
       open lsb1
       fetch lsb1 into @bb
        while @@fetch_status=0
        begin
          set @bb=@bb+1
          fetch lsb1 into @bb
        end
       close lsb1
      DEALLOCATE lsb1
    select @bb 
      

  4.   


    create table tb1(id int)
    insert into tb1 values(1)
    insert into tb1 values(2)
    insert into tb1 values(3)
    insert into tb1 values(4)
    insert into tb1 values(5)Create proc pp_ww
    as
    Begin
      declare @t table (a int )
      declare @tt int
      declare cur_name cursor  for select id  from tb1
      open cur_name
      fetch  cur_name into  @tt
      while @@fetch_status=0 
        begin
          insert into @t select @tt
           fetch   cur_name  into @tt
        End
      Close cur_name
      deallocate cur_name
      select * from @t
     
    End
    exec pp_ww
    drop proc pp_ww
    drop table tb1
    '1
    2
    3
    4
    5
    '
      

  5.   

       while @@fetch_status=0