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
原文地址:https://www.cnblogs.com/hz1234/p/6255590.html