Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
GauravRahi
Starting Member
1 Post |
Posted - 2011-01-18 : 18:06:55
|
| I am running the following query. It is ending up in a deadlock situation where it is running endlessly. Appriciate for an early answer select distinct (TCLE.ErrorID) from #TEMPCHECKLISTERROR TCLE left join cl_SessionHasIndexValue SHIV1(NOLOCK)on NULLIF(LTRIM(RTRIM(TCLE.PolicyNumber)), '') is not null and SHIV1.IndexValue=TCLE.PolicyNumber left join cl_SessionHasIndexValue SHIV2 (NOLOCK)on NULLIF(LTRIM(RTRIM(TCLE.PolicyNumber)), '') is null and NULLIF(LTRIM(RTRIM(TCLE.AgentNumber)), '') is not null and SHIV2.IndexValue=TCLE.AgentNumber left join cl_SessionHasIndexValue SHIV3 (NOLOCK)on NULLIF(LTRIM(RTRIM(TCLE.PolicyNumber)), '') is null and NULLIF(LTRIM(RTRIM(TCLE.AgentNumber)), '') is null and NULLIF(LTRIM(RTRIM(TCLE.GroupNumber)), '') is not null and SHIV3.IndexValue=TCLE.GroupNumber inner join cl_checklistResults CLR (NOLOCK) on TCLE.ErrorMessage=CLR.displayText and TCLE.Source=CLR.Sourcewhere CLR.currentstatuscode <>99 and dbo.indextoSession(COALESCE(SHIV1.cl_sessionid,SHIV2.cl_sessionid,SHIV3.cl_sessionid,NULL),TCLE.PolicyNumber,TCLE.AgentNumber,TCLE.GroupNumber) =1 )The query above calls a function indextosession that is actually creating the problem, i guess. Here is the clode belowset QUOTED_IDENTIFIER ONgoALTER FUNCTION [dbo].[indextoSession] (@Sessionid bigint,@Policynumber varchar(30), @AgentNumber varchar(30), @GroupNumber varchar(30) )returns bitAsBEGINDeclare @count intDeclare @sessionIndexCount intDeclare @returnValue bitset @count=0IF NULLIF(LTRIM(RTRIM(@policynumber)), #39;#39;) is not nullbeginset @count=@count+1endIF NULLIF(LTRIM(RTRIM(@agentnumber)), #39;#39;) is not nullbeginset @count=@count+1endIF NULLIF(LTRIM(RTRIM(@groupnumber)), #39;#39;) is not nullbeginset @count=@count+1endselect @sessionIndexCount=count(*) from dbo.cl_SessionHasIndexValue with (nolock) where cl_sessionid =@Sessionidif @SessionIndexCount >=@countset @returnValue =1elseset @returnValue =0return (@returnValue)ENDGaurav Rahi |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|
|