troubleshooting Question

SQL Server Deadlock Lock chosen for fail

Avatar of Larry Brister
Larry BristerFlag for United States of America asked on
Microsoft SQL ServerRemote Access
10 Comments1 Solution98 ViewsLast Modified:
The code below  is part of a SQL Job and periodically fails as the deadlock victim

Is there a way I can stop this?

Perhaps with an "If Exists ...

Or just putting a Print statement after the first update?

I changed this...
--sometimes the amount ends with just a . not .00

UPDATE ewPayments
SET    Amount = REPLACE(Amount, '.', '.00')
WHERE  RIGHT(Amount, 1) = '.';

UPDATE ewPaymentsActivity
SET    Amount = REPLACE(Amount, '.', '.00')
WHERE  RIGHT(Amount, 1) = '.';

To This
--sometimes the amount ends with just a . not .00
-- LB  Job had excessive amount of deadlock fails.
-- Previous code is archived after current

IF EXISTS (   SELECT 1
              FROM   ewPayments WITH ( NOLOCK )
              WHERE  RIGHT(Amount, 1) = '.' )
    BEGIN
        UPDATE ewPayments
        SET    Amount = REPLACE(Amount, '.', '.00')
        WHERE  RIGHT(Amount, 1) = '.';
    END;

IF EXISTS (   SELECT 1
              FROM   ewPaymentsActivity WITH ( NOLOCK )
              WHERE  RIGHT(Amount, 1) = '.' )
    BEGIN
        UPDATE ewPaymentsActivity
        SET    Amount = REPLACE(Amount, '.', '.00')
        WHERE  RIGHT(Amount, 1) = '.';
    END;


/*
UPDATE ewPayments
SET    Amount = REPLACE(Amount, '.', '.00')
WHERE  RIGHT(Amount, 1) = '.';

UPDATE ewPaymentsActivity
SET    Amount = REPLACE(Amount, '.', '.00')
WHERE  RIGHT(Amount, 1) = '.';
*/

Screen Print
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros