Try:
IF (OBJECT_ID('tempdb..#trans') IS NOT NULL)
DROP TABLE #trans;
CREATE TABLE #trans
(
acct_nbr VARCHAR(128)
, tran_dt DATETIME
, tran_amt DECIMAL(38, 2)
, tran_type1 VARCHAR(128)
, tran_type2 VARCHAR(128)
, tran_id VARCHAR(128)
, tran_id_decline VARCHAR(128)
);
INSERT INTO
#trans (acct_nbr, tran_dt, tran_amt, tran_type1, tran_type2, tran_id)
VALUES
('111', '2022-05-08 11:08:47.257', '1.00', 'C', 'X', 'ID-01')
, ('111', '2022-05-08 11:08:47.257', '1.00', 'A', '', 'ID-02')
, ('111', '2022-05-09 11:10:47.257', '1.00', 'A', '', 'ID-03')
, ('111', '2022-05-09 11:11:11.257', '1.00', 'P', 'O', 'ID-04')
, ('111', '2022-05-09 13:11:33.123', '1.00', 'A', 'X', 'ID-05')
, ('111', '2022-05-09 14:10:47.257', '1.00', 'A', '', 'ID-06')
, ('111', '2022-05-09 14:11:17.257', '1.00', 'P', 'O', 'ID-07')
, ('111', '2022-05-09 14:11:48.257', '1.00', 'P', 'O', 'ID-08')
, ('222', '2022-05-10 11:09:47.257', '1.00', 'A', '', 'ID-09')
, ('222', '2022-05-10 11:09:47.257', '1.00', 'A', '', 'ID-10')
, ('222', '2022-05-10 11:09:57.257', '1.00', 'P', 'O', 'ID-11')
, ('222', '2022-05-10 11:09:57.257', '1.00', 'P', 'O', 'ID-12')
, ('333', '2022-05-10 11:09:47.257', '1.00', 'A', '', 'ID-13')
, ('333', '2022-05-10 11:09:47.257', '1.00', 'A', '', 'ID-14')
, ('333', '2022-05-10 11:09:57.257', '1.00', 'P', 'O', 'ID-15');
IF (OBJECT_ID('tempdb..#tran_decline_notice') IS NOT NULL)
DROP TABLE #tran_decline_notice;
SELECT
*
INTO
#tran_decline_notice
FROM (SELECT * FROM #trans WHERE tran_type1 = 'P' AND tran_type2 = 'O') a;
SELECT * FROM #tran_decline_notice ORDER BY #tran_decline_notice.tran_id;
;WITH cte AS
(
SELECT
t.*
, d.tran_dt AS decline_dt
, d.tran_id AS tran_id_decline_ID
, ROW_NUMBER() OVER (PARTITION BY
t.acct_nbr
, t.tran_amt
, t.tran_type1
, t.tran_id
ORDER BY
t.tran_id
) AS Rn
FROM
#trans t
LEFT JOIN #tran_decline_notice d
ON t.acct_nbr = d.acct_nbr
AND t.tran_amt = d.tran_amt
AND t.tran_dt BETWEEN DATEADD(SECOND, -60, d.tran_dt) AND d.tran_dt
AND t.tran_type1 = 'A'
)
, cte2 AS
(
SELECT
*
, ROW_NUMBER() OVER (PARTITION BY
cte.acct_nbr
, cte.tran_amt
, cte.tran_type1
, cte.tran_id_decline_ID
ORDER BY
cte.tran_id_decline_ID
, Rn
) AS Rn2
FROM
cte
)
MERGE #trans t
USING cte2 AS src
ON t.tran_id = src.tran_id
AND src.Rn2 = 1
WHEN MATCHED AND t.tran_type1 = 'A' THEN
UPDATE SET
t.tran_id_decline = src.tran_id_decline_ID;
SELECT * FROM #trans;