内嵌游标问题
执行游标一直执行没反应,是什么问题呢。
Alter procedure P_getFlowRecordBySearch
(
@ordNo varchar(50),
@systemCode varchar(50),
@uid varchar(30),
@beginDt datetime,
@endDt datetime,
@status varchar(2),
@Applicant varchar(30)
)
As
Begin
Declare @temp table (Guid uniqueidentifier,status varchar(5))
Declare @Guid uniqueidentifier
Declare @node int
declare @isActionValue varchar(20)
declare @TempValue varchar(20)
declare mycurosr cursor for
select GUID ,ordNo ,node from sysFlow where applicant = @applicant and uid >= @beginDt and uid <= @endDt
open mycurosr
fetch next from mycurosr into @Guid,@ordNo,@node
while @@fetch_status = 0
set @TempValue = ''
declare TempCursor cursor for select isnull(isAction,'N') from sysflow where ordNo = @ordNo group by isAction
open TempCursor
fetch next from TempCursor into @isActionValue
while @@fetch_status = 0
declare @RowCount1 int
declare @RowCount11 int
declare @RowCount2 int
declare @RowCount22 int
set @TempValue = @TempValue + @isActionValue
if(@TempValue = 'N')
insert into @temp(Guid,status) values (@Guid,'N')--待处理
if @TempValue ='Y'
insert into @temp(Guid,status) values (@Guid,'Y')--已完成
if len(@TempValue) >= 2
select @RowCount1 = count(*) from sysflow where ordNo = @ordNo and node =@node -1 and isaction is not null and actionDate is not null
select @RowCount11 = count(*) from sysflow where ordNo = @ordNo and Applicant = @applicant and isAction is null and actionDate is null
if @RowCount1 = 1 and @RowCount11 = 1
insert into @temp(Guid,status) values (@Guid,'R')--处理中
select @RowCount2 = count(*) from sysflow where ordNo = @ordNo and Applicant = @applicant and isAction is not null and actionDate is not null
select @RowCount22 = count(*) from sysflow where ordNo = @ordNo and node = @node + 1 and isaction is null and actionDate is null
if @RowCount2 = 1 and @RowCount22 = 1
insert into @temp(Guid,status) values (@Guid,'F')--已处理
fetch next from TempCursor into @isActionValue
close TempCursor
fetch next from mycurosr into @Guid ,@ordNo ,@node
select distinct A.GUID as Id,A.ordNo,A.systemName,A.FrmName,
dbo.f_getUserChineseNameBySysFlowUid(A.uid) as uid,A.uidDt as uidDt,dbo.f_getCurrentApprovers(A.ordNo) as CurrentApprove,ActionDate,
dbo.f_getCurrentApproversStatus(A.ordNo) as Status,dbo.f_getIsApprove(A.ordNo,A.Applicant) as IsApprove
from sysflow A inner join @temp B on A.guid = B.Guid
where A.ordNo = isnull(@ordNo,A.ordNo)
and A.systemCode = isnull(@systemCode,A.systemCode)
and A.uid = isnull(@uid,A.uid) and A.uidDt >= isnull(@beginDt,A.uidDt)
and A.uidDt <= isnull(@endDt,A.uidDt)
and A.Applicant = isnull(@Applicant,A.Applicant)
and B.status = isnull(@status,B.status)
order by A.uidDt desc
close mycurosr
End