First, combine data
UPDATE branchMaster set charterNumber = @To_CharterNumber, branchID = branchId + (SELECT MAX(branchID) FROM branchMaster WHERE charterNumber = @To_CharterNumber) WHERE charterNumber = @From_CharterNumber
Second, sort branchID
UPDATE branchMaster SET branchID = t2.id
FROM branchMaster t1,
(SELECT a.branchID, id = COUNT(a.branchID)
FROM branchMaster a,branchMaster b
WHERE a.charterNumber = b.charterNumber
AND a.branchID >= b.branchID
AND a.charterNumber = @To_CharterNumber
GROUP BY a.branchID) t2
WHERE t1.branchID = t2.branchID
AND t1.charterNumber = @To_CharterNumber
UPDATE branchMaster set charterNumber = @To_CharterNumber, branchID = branchId + (SELECT MAX(branchID) FROM branchMaster WHERE charterNumber = @To_CharterNumber) WHERE charterNumber = @From_CharterNumber
Second, sort branchID
UPDATE branchMaster SET branchID = t2.id
FROM branchMaster t1,
(SELECT a.branchID, id = COUNT(a.branchID)
FROM branchMaster a,branchMaster b
WHERE a.charterNumber = b.charterNumber
AND a.branchID >= b.branchID
AND a.charterNumber = @To_CharterNumber
GROUP BY a.branchID) t2
WHERE t1.branchID = t2.branchID
AND t1.charterNumber = @To_CharterNumber