Home > Software engineering >  SQL Server Express LocalDB: update a value if it begins with a certain digit
SQL Server Express LocalDB: update a value if it begins with a certain digit

Time:05-19

We are currently storing a load of customer mobile numbers, however most of them are missing the leading 0.

How can I add a 0 in SQL to the front of all mobile numbers where the first digit equals 7?

CodePudding user response:

You may use LIKE here:

UPDATE yourTable
SET mobile = '0'   mobile
WHERE mobile LIKE '7%';

CodePudding user response:

You can write a concat statement

update table
set yourcolumn = CONCAT('0', yourcolumn)
where yourcolumn like '7%'
  • Related