I'm having difficulties updating a result set depending on some condition. Some of the account numbers come in empty but match based on a different identifier.
I'm updating the empty account numbers with the matching one, but can't quite get the syntax to work. I'm running into the error
The multi-part identifier "CMRR.aacount_number' could not be found
This is at a few different places I'm referencing the other table.
DECLARE @BatchId INT
SET @BatchId = 1030
SELECT 
    CMRR.id,
    CMRR.account_number,
    CMRR.URN
FROM 
    CRA_METRO2_REJECTED_RECORDS AS CMRR
WHERE 
    batch_id = @BatchId
IF CMRR.account_number = ''
BEGIN
    UPDATE CRA_METRO2_REJECTED_RECORDS 
    SET CMRR.account_number = (SELECT account_number 
                               FROM CRA_METRO2_REJECTED_RECORDS
                               WHERE URN = CMRR.URN
                                  AND account_number != '')
    WHERE id = CMRR.id
END
 
     
    