首页 > 代码库 > sql 2008 游标

sql 2008 游标

    begin
        declare PlatformBulletin --定义游标
        cursor for select UserID,ZMSCompanyID from base_UserCompany where isActive = 1
        
        open PlatformBulletin --打开游标
        declare @userid int,@zmscompanyid int
        
        fetch next from PlatformBulletin into @userid,@zmscompanyid
        while (@@fetch_status=0)
        begin
            insert into oa_BulletinUser(BulletinID,AttachmentGUID,ToUserID,IsRead,ReadTime,CreateTime,ZMSCompanyID) 
                values(@bulletinid,‘‘,@userid,0,null,GETDATE(),@zmscompanyid)
                
            fetch next from PlatformBulletin into @userid,@zmscompanyid
        end
        
        close PlatformBulletin --关闭游标
        deallocate PlatformBulletin --释放游标
    end

 

sql 2008 游标