February 8, 2008 at 6:39 am
Hi Guys,
Im pretty new to SQL and I need to perform a task where I have to replace the leading 0 with 44.
E.g 01329225558 would become 441328225558.
I have tried many times but all of my results end up in me changing every 0 in the data.
Any ideas how to just change this leading 0.
Cheers
matt
February 8, 2008 at 6:52 am
UPDATE [TableName]
SET [ColumnName] = '44' + RIGHT([ColumnName], LEN([ColumnName]) - 1)
Add...
WHERE [ColumnName] LIKE '0%'
...if not all entries begin with 0 and so you need to restrict to the ones that do, otherwise don't.
February 8, 2008 at 6:59 am
Another way
UPDATE [TableName]
SET [ColumnName] = STUFF([ColumnName],1,1,'44')
WHERE [ColumnName] LIKE '0%'
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537February 8, 2008 at 8:25 am
Thanks Guys,
Works a treat!!
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply