I typically work with Oracle, and a query like this would be very easy. I have googled my brains out. Basically it is to get the max identifier of the prior records of comments.
In Oracle I would have done an update like this
UPDATE NOTES N1
SET MASTER_RECORD_NUMBER =
(SELECT MAX(MASTER_RECORD_NUMBER)
FROM NOTES N2
WHERE N1.CUSTOMER_NO = N2.CUSTOMER_NO
AND N2.MASTER_RECORD_NUMBER < N1.MASTER_RECORD_NUMBER
AND N2.CODE IS NOT NULL)
WHERE N1.CODE IS NULL;
Basically the record numbers are sequential, and the code is not present if it is a continuation. The query is a little longer than this, involving dates and such, but this is generally what I am trying to do.