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

 

posted on 2017-01-06 11:19  路人甲zzz  阅读(107)  评论(0编辑  收藏  举报

导航