码迷,mamicode.com
首页 > 数据库 > 详细

循环处理--sqlserver

时间:2015-10-12 12:24:37      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

alter PROCEDURE [dbo].[sp_gongzi] @gongzi_yf varchar(7) as
DECLARE  @input_id varchar(20)
DECLARE  @sk_sum decimal(18, 3)
DECLARE  @sk_sum_yk decimal(18, 3)
BEGIN 
    DECLARE cur_input CURSOR  FOR
            select docno from  tc_tab1 where yf = @gongzi_yf    
 
 OPEN cur_input
 
    FETCH  cur_input INTO @input_id
 WHILE @@FETCH_STATUS = 0
      BEGIN
         set @sk_sum = 0    
         set @sk_sum_yk  = 0
         select @sk_sum =  sum(je * case when (hl2 is null) then hl else hl2 end )         
             from sk_dan where docno =@input_id;
        
         select @sk_sum_yk =  sum(je * case when (hl2 is null) then hl else hl2 end )         
             from sk_dan_yk where docno =@input_id;       
               
        set @sk_sum = case when (@sk_sum is null) then 0 else @sk_sum end;       
        set @sk_sum_yk =  case when (@sk_sum_yk is null) then 0 else @sk_sum_yk end;       
       
        update    tc_tab1 set dke2 =  @sk_sum   +   @sk_sum_yk
     where docno = @input_id; 
       
   FETCH  cur_input INTO @input_id
      END
    CLOSE cur_input
    DEALLOCATE cur_input 
    --*/
END

循环处理--sqlserver

标签:

原文地址:http://www.cnblogs.com/szlixin/p/4870944.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!