Ok this general problem has reared its ugly head twice in the past 6 months (different stored procedure). We have our internal users report a timeout error in the application. We can reproduce the problem in the application in a controlled environment. So we go through the normal steps of checking for blocking using sp_who2. Everything looks good with no blocking. So we do a sql trace to see exactly how the procedure is being executed. We copy that to a new window in SQL Management Studio and execute what sql trace was telling us ADO.Net was doing it and it finished in milliseconds. Our applications timeout is 30 seconds. When this problem happened a couple months back we had SQL Server 2005. We now have upgraded to SQL Server 2008 R2. Whats the next step to diagnose a problem like this?
@Martin: Thanks for the response. I will read your post in detail and let you know what i found out. Until then here is the sql in the SP you requested:
Select
@Exists=0,
@EarnRecId=0,
@SuppStatusId = 0,
@SLRecId = 0,
@EarnRecDS = Null
Select
@EarnRecId = er.EarningsId,
@EarnRecDS = Convert(Varchar(26),er.Datestamp, 109),
@SuppStatusId = s.SuppStatusId,
@SLRecId = s.SLId
From
Tracking tr
Inner Join Supps s On s.SuppId = tr.SuppId
Inner Join Earnings er On er.EarnRecId = s.SuppId
Where
tr.ClaimId = @ClaimId
and er.FiscalYr = @FiscalYr
And er.EmplyrId In (@EmpId1,@EmpId2)
If @EarnRecId > 0
Begin
Set @Exists=1
End