I have a column of ZIP codes, some of which I need to add a leading zero to in order to make it five digits and some of which are blank and need to be populated with five zeroes. How do I do both in one update query?
Thanks!
Concatenate 5 zeroes to the start of the Zip code value, and take the right-most 5 characters from that combined string.
UPDATE YourTable
SET zip_code = Right('00000' & zip_code, 5)
WHERE Len(Trim(zip_code & '')) < 5;
I assumed the zip_code field is text type because storing leading zeroes doesn't make sense for numeric data. If the field is numeric, you could just use a Format() expression to display the leading zeroes.
The WHERE clause limits the UPDATE to only those rows where zip_code is Null or less than 5 characters.
WHERE clause excludes rows whose zip_code values include 5 or more characters. So your stored ZIP+4 values will not be changed. Is there a problem I'm not seeing?