SQLSERVER存储过程改为DB2存储过程

CREATE   PROCEDURE   sp抄表   (@jsrq   nvarchar(50))   AS  
  declare   @dybh   nvarchar(50),@bmc   nvarchar(50),@scds   money,@bcds   money,@xd   money,@cbzzrq   nvarchar(50),@jfbz   bit,@gq   bit  
  declare   @ycbbz   bit,@bl   float,@lc   tinyint   ,@bz   nvarchar   (50),@bh   nvarchar   (50),@fb   nvarchar   (50),@zdyl   int,@zgyl   int  
  declare   mycunit   cursor   for   select   单元编号,表名称,上次读数,本次读数,行度,抄表终止日期,计费标志,挂起,已抄表标志,倍率,量程,备注,编号,父表,最低用量,最高用量   from   单元表抄表   where   抄表终止日期='<当前抄表期间>'  
  declare   mycpub   cursor   for   select   表名称,上次读数,本次读数,行度,抄表终止日期,计费标志,挂起,已抄表标志,倍率,量程,备注   from   公用表抄表   where   抄表终止日期='<当前抄表期间>'  
   
  open   mycunit  
  fetch   next   from   mycunit   into   @dybh,@bmc,@scds,@bcds,@xd,@cbzzrq,@jfbz,@gq,@ycbbz,@bl,@lc,@bz,@bh,@fb,@zdyl,@zgyl  
  while   @@fetch_status=0  
  begin  
  insert   into   单元表抄表   (单元编号,表名称,上次读数,本次读数,行度,抄表终止日期,计费标志,挂起,已抄表标志,倍率,量程,备注,编号,父表,最低用量,最高用量)    
  values(@dybh,@bmc,@scds,@bcds,@xd,@jsrq,0,0,@ycbbz,@bl,@lc,@bz,@bh,@fb,@zdyl,@zgyl)    
  fetch   next   from   mycunit   into   @dybh,@bmc,@scds,@bcds,@xd,@cbzzrq,@jfbz,@gq,@ycbbz,@bl,@lc,@bz,@bh,@fb,@zdyl,@zgyl  
  end  
  close   mycunit  
  deallocate   mycunit  
   
  open   mycpub  
  fetch   next   from   mycpub   into   @bmc,@scds,@bcds,@xd,@cbzzrq,@jfbz,@gq,@ycbbz,@bl,@lc,@bz  
  while   @@fetch_status=0  
  begin  
  insert   into   公用表抄表   (表名称,上次读数,本次读数,行度,抄表终止日期,计费标志,挂起,已抄表标志,倍率,量程,备注)    
  values(@bmc,@scds,@bcds,@xd,@jsrq,0,0,@ycbbz,@bl,@lc,@bz)    
  fetch   next   from   mycpub   into   @bmc,@scds,@bcds,@xd,@cbzzrq,@jfbz,@gq,@ycbbz,@bl,@lc,@bz  
  end  
  close   mycpub  
  deallocate   mycpub  
   
  update   单元表抄表   set   上次读数=本次读数,行度=0   where   抄表终止日期='<当前抄表期间>'  
  update   公用表抄表   set   上次读数=本次读数,行度=0   where   抄表终止日期='<当前抄表期间>'   
 

DB2

CREATE   PROCEDURE   sp抄表   (in   jsrq   nvarchar(50))    
  begin  
            declare   dybh   nvarchar(50);  
            declare   bmc   nvarchar(50);  
            declare   scds   money;  
            declare   bcds   money;  
            declare   xd   money;  
            declare   cbzzrq   nvarchar(50);  
            declare   jfbz   bit;  
            declare   gq   bit;  
            declare   ycbbz   bit;  
            declare   bl   float;  
            declare   lc   tinyint;  
            declare   bz   nvarchar(50);  
            declare   bh   nvarchar(50);  
            declare   fb   nvarchar(50);  
            declare   zdyl   int;  
            declare   zgyl   int;  
            declare   rcount   int;  
            declare   i   int;  
            declare   mycunit   cursor   for   select   单元编号,表名称,上次读数,本次读数,行度,抄表终止日期,计费标志,挂起,已抄表标志,倍率,量程,备注,编号,父表,最低用量,最高用量   from   单元表抄表   where   抄表终止日期='<当前抄表期间>';  
            declare   mycpub   cursor   for   select   表名称,上次读数,本次读数,行度,抄表终止日期,计费标志,挂起,已抄表标志,倍率,量程,备注   from   公用表抄表   where   抄表终止日期='<当前抄表期间>';  
   
            set   i=1;  
            select   count(*)   into   rcount   from   单元表抄表   where   抄表终止日期='<当前抄表期间>';  
            open   mycunit;  
            while   i<=rcount   do            
  insert   into   单元表抄表   (单元编号,表名称,上次读数,本次读数,行度,抄表终止日期,计费标志,挂起,已抄表标志,倍率,量程,备注,编号,父表,最低用量,最高用量)   values(dybh,bmc,scds,bcds,xd,jsrq,0,0,ycbbz,bl,lc,bz,bh,fb,zdyl,zgyl);    
                  fetch   mycunit   into   dybh,bmc,scds,bcds,xd,cbzzrq,jfbz,gq,ycbbz,bl,lc,bz,bh,fb,zdyl,zgyl;  
                  set   i=i+1;  
            end   while;  
            close   mycunit;  
   
            set   i=1;  
            select   count(*)   into   rcount   from   公用表抄表   where   抄表终止日期='<当前抄表期间>';  
            open   mycpub;  
            while   i<=rcount   do  
  insert   into   公用表抄表   (表名称,上次读数,本次读数,行度,抄表终止日期,计费标志,挂起,已抄表标志,倍率,量程,备注)   values(bmc,scds,bcds,xd,jsrq,0,0,ycbbz,bl,lc,bz);    
  fetch   mycpub   into   bmc,scds,bcds,xd,cbzzrq,jfbz,gq,ycbbz,bl,lc,bz;  
                  set   i=i+1;  
          end   while;  
          close   mycpub;  
   
          update   单元表抄表   set   上次读数=本次读数,行度=0   where   抄表终止日期='<当前抄表期间>';  
          update   公用表抄表   set   上次读数=本次读数,行度=0   where   抄表终止日期='<当前抄表期间>';  
  end  

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值