Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15694

How to resolve the deadlock for stored procedure ?

$
0
0

Hi,

I am facing deadlock issues in one procedure ... as code is likewise....

DECLARE

@T table (Ticketid bigint, RefTaskId bigint)

INSERT INTO @T

select distinct TicketId,replace(left(RefTaskId,16),',','') RefTaskId

from Extjs_A b with(nolock)

inner join jmgtjob a with(nolock) on TicketId = jobid and a.status = 5 and a.CategoryName = 'device-down'

where b.status <> 'closed' and b.CategoryName = 'device-down' and @flag > 0

delete @T

from Extjs_A b with(nolock)

inner join @T a on a.TicketId = b.Ticketid

inner join NOC_devicedownAllDetail nd with(nolock) on RefTaskId = nd.taskid

where b.status <> 'closed' and nd.ProcessStatus <> 'closed'

SELECT count(*) FROM @T

IF @@rowcount > 0

BEGIN

UPDATE Extjs_A

SET status = 'Closed' ,

SystemComments

= 'Closed By System Because Alert is autoclosed',

CallCompletedTime

= ISNULL(CallCompletedTime ,getdate()) ,

Userid

= -5

FROM Extjs_A b with(nolock)

INNER JOIN @T a on a.TicketId = b.Ticketid

WHERE b.CategoryName = 'device-down' AND b.status <> 'closed'

END

DECLARE @T1 table(CQReferenceID bigint)

insert into @T1

Select CQReferenceID

FROM noc_devicedownalldetail WITH(NOLOCK)

where TicketID > @id

GROUP BY CQReferenceID

Having count(CASE WHEN ProcessStatus = 'Closed' THEN 1 END) = count(*)

--option(optimize for(@id = null))

IF Exists

(

SELECT 1

FROM extjs_A E WITH (NoLock)

INNER JOIN @T1 N ON E.TicketId = N.CQReferenceID

WHERE Status <> 'Closed'

)

BEGIN

Update extjs_A

SET Status = 'Closed',

CallCompletedTime

= ISNULL(CallCompletedTime,getdate()),

SystemComments

= 'Closed by System As Per Close Condition (From Maintenace exe).' ,

UserID

= -5

FROM extjs_A E WITH (NoLock)

INNER JOIN

(

Select CQReferenceID

FROM noc_devicedownalldetail WITH(NOLOCK)

GROUP BY CQReferenceID

Having count(CASE WHEN ProcessStatus = 'Closed' THEN 1 END) = count(*)

) N ON E.TicketId = N.CQReferenceID

WHERE Status <> 'Closed'

END -----------------Please tell me me suggest for same.Thanks


Viewing all articles
Browse latest Browse all 15694

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>