tags:

views:

42

answers:

1

I have a ZIP code column where some of the zips came in without the leading zero.

My goal is to:

1) select all rows in the zip column that are four characters in length (e.g. the zip code entries missing a zero)

and then

2) append a '0' to these columns.

I am able to select the rows:

SELECT zip FROM contact WHERE zip LIKE "____";

and I found on this site how to append the '0':

UPDATE contact SET zip = Concat('0', zip);

but how do I combine them both together into one query?

Thanks.

+3  A: 

Like this:

UPDATE contact
SET zip = Concat('0', zip)
WHERE zip LIKE "____";

You can also do it like this:

UPDATE contact
SET zip = Concat('0', zip)
WHERE LEN(zip) = 4;
Paul
+1 faster than me
Rory