w3n2u w3n2u - 7 months ago 12
SQL Question

How to remove the first character if it is a specific character in SQL

I currently have a table

Telephone
it has entries like the following:

9073456789101
+773456789101
0773456789101


What I want to do is remove only the 9 from the start of all the entries that have a 9 there but leave the others as they are.

any help would be greatly appreciated.

Answer

While all other answer are probably also working, I'd suggest to try and use STUFF function to easily replace a part of the string.

UPDATE Telephone
SET number = STUFF(number,1,1,'')
WHERE number LIKE '9%'

SQLFiddle DEMO