View Full Version : Update and Replace

07-30-2011, 06:00 PM
Would I be right in saying that the following update statement will replace 1 with 01 and 14 with 014.

I only want it to replace 1 with 01 - how do I achieve this?

update bookings set eventMonth = replace(eventMonth, '1', '01')

Old Pedant
07-30-2011, 10:44 PM
Ummm...it depends on what kind of field eventMonth is.

If eventMonth is an integer, for example, either that code will do nothing or it will cause an error.

But if eventMonth is a text field of some kind, you are correct.

But why not find out?

SELECT replace(eventMonth,'1','01') FROM bookings

What do you get?