游标的使用



    declare @count int ;
    declare @curid varchar(50); --存放游标id
    declare @createdate datetime;
    declare @str varchar(max);
    
    declare @date1 datetime;
    declare @date2 datetime;
    declare @proce1 int;
    declare @proce2 int;
    set @str='';
    
declare cursor1 cursor for--定义游标
select ID,Createdate from E_Boiler   WHERE  deletemark=1; 
open cursor1 
fetch next from cursor1 into @curid,@createdate
while @@FETCH_STATUS=0 
begin
    select @count=COUNT(1) from E_OA_Deal where OAID=@curid  
    if(@count >0)
    begin
declare cursor2 cursor for--定义游标
       select createdate,dealprocess from E_OA_Deal where OAID=@curid order by CreateDate 
       open cursor2 
fetch next from cursor2 into @date2,@proce2
   set  @date1=@createdate;
while @@FETCH_STATUS=0 
begin
  if(@proce2=0) 
  begin
      if(DATEDIFF(DAY,@date1,@date2)>5)
      begin
       set @str =@str + 'SELO  处理超期';
      end
  end
  else if (@proce2=1) 
  begin
      if(DATEDIFF(DAY,@date1,@date2)>5)
      begin
       set @str =@str + '业务处处理超期';
       end
  end
   else if (@proce2=2) 
  begin
      if(DATEDIFF(DAY,@date1,@date2)>5)
      begin
       set @str =@str + '主管处长处理超期';
       end
  end
   else if (@proce2=3) 
  begin
      if(DATEDIFF(DAY,@date1,@date2)>5)
      begin
       set @str =@str + 'SELO  处理超期';
       end
  end
   else if (@proce2=4) 
  begin
      if(DATEDIFF(DAY,@date1,@date2)>5)
      begin
       set @str =@str + 'SELO  处理超期';
       end
  end
   
set @date1=@date2
fetch next from cursor2 into @date2,@proce2
 
end
close cursor2 
deallocate cursor2 
--判断是否是4结束
    end
    else begin
if(DATEDIFF(DAY,@createdate,getdate())>5)
begin
set @str =@str + 'SELO 处理超期'; 
end 
    end
    
fetch next from cursor1 into @curid,@createdate
end
close cursor1  
deallocate cursor1 

select @str;
select createdate,dealprocess from E_OA_Deal where OAID='7F90BA2C-CE2D-480C-99E3-2FC3B4A226BF' order by CreateDate

select * from E_Boiler
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值