Update from a Set Select Statement

Hi experts,
I'm trying to update Zip so that it only contains the left-most 5 characters.
The code below changed all zip to null values.

Do I need to use a JOIN?

UPDATE MyTable
SET Zip = (SELECT LEFT(Zip, 5)
WHERE Country = 'UNITED SATES');

Thanks

UPDATE MyTable
SET Zip = LEFT(Zip, 5)
WHERE Country = 'UNITED SATES';
1 Like

WHERE Country = 'UNITED ST
ATES';

Thanks @robert_volk !


UPDATE MyTable
SET Zip = LEFT(Zip, 5)
WHERE Country = 'UNITED STATES' AND LEN(Zip) > 5
1 Like