34,594
社区成员
发帖
与我相关
我的任务
分享
declare @i nvarchar(20) ---IVRData 的数据类型
declare @j nvarchar(20) ---SessionID的数据类型
declare @k nvarchar(20) ---ExitState的数据类型
set @i=SessionID --给SessionID 赋值
select @k=ExitState,@j=(case when IVRData<>'' then 'PJ=2' else IVRData end),Direction
from table a,
where a.SessionID=@i
and a.SequenceID=(select max(SequenceID) from table b where a.SessionID=b.SessionID )
if(@j<>'')
begin
select SessionID,SequenceID,TalkDuration,@ExitState,(case when IVRData<>'' then 'PJ=2' else IVRData end) IVRData ,Direction
from table a,
where a.SessionID=@i
and a.SequenceID=(select max(SequenceID) from table b where a.SessionID=b.SessionID )
end
if (@j='' and @k=1)
begin
select top 1 a.*
from table a
where a.SessionID<=@i --等于号自己决定
and a.SequenceID=(select max(SequenceID) from table b where a.SessionID=b.SessionID )
and a.IVRData=''
and a.ExitState=1
and (case when TalkDuration>0 then 1 else 0 end)+(case when Direction=1 then 1 else 0 end)<>2
order by a.SessionID desc
end
declare @i nvarchar(20) ---IVRData 的数据类型
declare @j nvarchar(20) ---SessionID的数据类型
set @i=SessionID --给SessionID 赋值
select SessionID,SequenceID,TalkDuration,ExitState,@j=(case when IVRData<>'' then 'PJ=2' else IVRData end),Direction
from table a,
where a.SessionID=@i
and a.SequenceID=(select max(SequenceID) from table b where a.SessionID=b.SessionID )
if @j=''
begin
select top 1 a.*
from table a
where a.SessionID<=@i --等于号自己决定
and a.SequenceID=(select max(SequenceID) from table b where a.SessionID=b.SessionID )
and a.IVRData=''
and a.ExitState=1
and (case when TalkDuration>0 then 1 else 0 end)+(case when Direction=1 then 1 else 0 end)<>2
order by a.SessionID desc
end
[/Quote]
declare @i nvarchar(20) ---IVRData 的数据类型
declare @j nvarchar(20) ---SessionID的数据类型
declare @k nvarchar(20) ---ExitState的数据类型
set @i=SessionID --给SessionID 赋值
select SessionID,SequenceID,TalkDuration,@k=ExitState,@j=(case when IVRData<>'' then 'PJ=2' else IVRData end),Direction
from table a,
where a.SessionID=@i
and a.SequenceID=(select max(SequenceID) from table b where a.SessionID=b.SessionID )
if (@j='' and @k=1)
begin
select top 1 a.*
from table a
where a.SessionID<=@i --等于号自己决定
and a.SequenceID=(select max(SequenceID) from table b where a.SessionID=b.SessionID )
and a.IVRData=''
and a.ExitState=1
and (case when TalkDuration>0 then 1 else 0 end)+(case when Direction=1 then 1 else 0 end)<>2
order by a.SessionID desc
end
[/Quote]
declare @i nvarchar(20) ---IVRData 的数据类型
declare @j nvarchar(20) ---SessionID的数据类型
set @i=SessionID --给SessionID 赋值
select SessionID,SequenceID,TalkDuration,ExitState,@j=(case when IVRData<>'' then 'PJ=2' else IVRData end),Direction
from table a,
where a.SessionID=@i
and a.SequenceID=(select max(SequenceID) from table b where a.SessionID=b.SessionID )
if @j=''
begin
select top 1 a.*
from table a
where a.SessionID<=@i --等于号自己决定
and a.SequenceID=(select max(SequenceID) from table b where a.SessionID=b.SessionID )
and a.IVRData=''
and a.ExitState=1
and (case when TalkDuration>0 then 1 else 0 end)+(case when Direction=1 then 1 else 0 end)<>2
order by a.SessionID desc
end