Question : Loop select statement and update rows with the results?

I have a table which holds addresses for customers, what I want to do is update a table using a select statement. I have attached the seperate queries.

How can I loop through so all customers addresses with code 9998 are updated with the phone number from their address with code 0000?

Thanks in advance.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
SELECT CUSTNMBR, ADRSCODE, PHONE1
FROM RM00102 
WHERE (ADRSCODE = '0000')
 
UPDATE RM00102 
SET PHONE1 = PHONE1 
WHERE (CUSTNMBR = CUSTNMBR) AND (ADRSCODE = '9998')

Answer : Loop select statement and update rows with the results?

hi, try this

UPDATE A
SET A.PHONE1 = B.PHONE1
FROM RM00102 A INNER JOIN RM00102 B ON (A.CUSTNMBR=B.CUSTNMBR)
WHERE A.ADRSCODE = '9998' AND B.ADRSCODE = '0000'
Random Solutions  
 
programming4us programming4us