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