Sql游标

ALTER proc [dbo].[FirstCreatePayFuture]
as
    declare @identity_id nvarchar(50);
    declare @count int;
    set    @count=0;
   DECLARE vendor_cursor CURSOR FOR select  distinct identity_id from dbo.T_Bills tb where  tb.identity_id!=''
    
  OPEN vendor_cursor --打开游标
    FETCH NEXT FROM vendor_cursor INTO @identity_id  --遍历数据
        while (@@FETCH_STATUS = 0)  --判断状态,0没有错误
          begin            
            set @count=@count+1;
            print @identity_id;
            FETCH NEXT FROM vendor_cursor INTO @identity_id --遍历数据
          end    
     CLOSE vendor_cursor --关闭游标
  DEALLOCATE vendor_cursor  --释放资源
  print @count;
  --使用游标 end
posted @ 2012-07-10 16:45  cn_king  阅读(133)  评论(0编辑  收藏  举报