Hi,@Mansoor Mohammed
Please also check this:
DECLARE @TestTable TABLE
(
SequenceNo int,
Name varchar(20),
CreditCardNumber varchar(20),
TransactionSequence int,
Transactions varchar(10),
Comment varchar(50)
);
INSERT INTO @TestTable VALUES
(1, 'xxx', '111111111', 1, 'Y', ''),
(2, 'xxx', '111111111', 2, 'Y', ''),
(3, 'yyy', '222222222', 1, 'Y', ''),
(4, 'yyy', '222222222', 2, 'E', ''),
(5, 'yyy', '222222222', 3, 'Y', ''),
(6, 'zzz', '333333333', 1, 'Y', ''),
(7, 'zzz', '333333333', 2, 'Y', ''),
(8, 'bla', '444444444', 1, 'Y', ''),
(9, 'bla', '444444444', 2, 'E', ''),
(10, 'bla', '444444444', 3, 'Y', ''),
(11, 'bla', '444444444', 4, 'Y', ''),
(12, 'bla', '444444444', 5, 'Y', '');
;WITH CTE AS
(
SELECT * FROM @TestTable
WHERE CreditCardNumber IN (SELECT CreditCardNumber FROM @TestTable WHERE Transactions = 'E')
AND TransactionSequence>=2
)
UPDATE CTE
SET Transactions = CASE WHEN Transactions = 'Y' THEN 'E' ELSE Transactions END,
Comment = CASE WHEN Transactions = 'Y'
THEN 'Comment2' ELSE 'Comment1' END;
SELECT * FROM @TestTable
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.