zoukankan      html  css  js  c++  java
  • 遍历表,执行存储过程的方法

    1、使用“表变量 ”

        declare @Row    int,

            @Rows    int,
            @DANo    char(23),
            @DATime    datetime,
            @LogTime datetime,
            @MeterType char(4),
            @MeterNo    char(20),
            @Qty        decimal(18,6)
    declare @t table (
    Row        int identity(1,1)    not null,
    DANo    char(23)            not null,
    DATime    datetime            not null,
    LogTime    datetime            not null,
    MeterType char(4)            not null,
    MeterNo      char(20)            not null,
    Qty        decimal(18,6)        null
    )
    insert into @t
    select DANo,DATime,LogTime,MeterType,MeterNo,Qty
    set @Rows = @@ROWCOUNT
    set @Row = 1
    while (@Row <=@Rows)
    begin
        select @DANo = DANo,@DATime= DATime,@LogTime= LogTime,@MeterType = MeterType,@MeterNo = MeterNo ,@Qty = Qty
        from @T where row = @Row
        
        exec Usp_DAListForEnergyDataDetail @DANo,@DATime,@LogTime,@MeterType,@MeterNo,@Qty
        
        set @Row = @Row + 1
    end

     

    2、使用游标

    declare cursor_test cursor local forward_only static read_only
    for
        select DANo,DATime,LogTime,MeterType,MeterNo,Qty from table_name

    open cursor_test
    fetch next from cursor_test into @DANo,@DATime,@LogTime,@MeterType,@MeterNo,@Qty

    while(@@fetch_status=0)
    begin
        exec Usp_DAListForEnergyDataDetail @DANo,@DATime,@LogTime,@MeterType,@MeterNo,@Qty
        fetch next from cursor_test into @DANo,@DATime,@LogTime,@MeterType,@MeterNo,@Qty
    end

    close cursor_test

    deallocate cursor_test 

  • 相关阅读:
    [BZOJ3997][TJOI2015]组合数学(Dilworth定理+DP)
    [BZOJ4000][TJOI2015]棋盘(状压DP+矩阵快速幂)
    BZOJ2462[Beijing2011]矩阵模板(二维Hash)
    [BZOJ2458][BeiJing2011]最小三角形(分治)
    [HDU5354]Bipartite Graph(CDQ分治+并查集)
    [NOIP2017]时间复杂度(模拟)
    [Luogu2540][NOIP2016]斗地主增强版(搜索+DP)
    [Luogu1979][NOIP2013]华容道(BFS+SPFA)
    WQS二分题集
    [CC-XXOR]Chef and Easy Problem
  • 原文地址:https://www.cnblogs.com/ssol/p/2604505.html
Copyright © 2011-2022 走看看