zoukankan      html  css  js  c++  java
  • SQLSERVER 游标

    ALTER PROCEDURE [dbo].[PROC_UpdMonthStatus]
    AS
        BEGIN
            declare @a int,
            @error int,
            @Id varchar(36),
            @Area varchar(200),
            @Department varchar(200),
            @Year INT,
            @Month INT
            
            set @a=1
            set @error=0
            
             --申明游标为Uid
            declare order_cursor cursor 
            for (select Id,Area,Department,ReportYear,ReportMonth from AreaMonthReport where Status=3)
            --打开游标--
            open order_cursor
             --开始循环游标变量--
            fetch next from order_cursor into @Id,@Area,@Department,@Year,@Month
            while @@FETCH_STATUS = 0    --返回被 FETCH语句执行的最后游标的状态--
                begin
                    ---添加一天办理记录            
                    DECLARE @CreatorId varchar(36)
                    SET @CreatorId=(select TOP 1 CreatorId from AuditOptions where AreaMonthReportId=@Id order by CreateTime desc)
                    insert into AuditOptions(ID,Link,CreateUser,CreatorId,OptionText,CreateTime,AreaMonthReportId)
                    values (NEWID(),'总部审核',@CreatorId,'','自动同意',GETDATE(),@Id)
                    --修改ProjectMonthTrack
                    update ProjectMonthTrack set ProjectStatus=5 where Area=@Area and Department=@Department and ReportYear=@Year and ReportMonth=@Month
                    --修改AreaMonthReport
                    update AreaMonthReport set Status=5 where Id=@Id
                    
                    
                    set @a=@a+1
                    set @error= @error + @@ERROR   --记录每次运行sql后是否正确,0正确
                    fetch next from order_cursor into @Id,@Area,@Department,@Year,@Month   --转到下一个游标,没有会死循环
                end   
        

        close order_cursor --关闭游标
        deallocate order_cursor -- 释放游标

     
        END
    GO

    以上代码主要实现了一条添加,以及2条修改记录

  • 相关阅读:
    Django——Model
    正则表达式
    day03数据类型
    创建一个 Django 项目
    JAVA获取MYSQL数据库表、字段、字段类型、字段注释
    Django
    取splist的某个字段的值
    如何获取列表项的创建者的邮件地址
    使用 HTML 表单 Web 部件筛选并显示另一 Web 部件中的数据
    vs2010+Aspx进行sharepoint2010工作流开发(1)
  • 原文地址:https://www.cnblogs.com/dushaojun/p/9288192.html
Copyright © 2011-2022 走看看