SQL "replace" syntax issue

113 Views Asked by At
UPDATE [Customers] 
  SET [Address] = REPLACE([Address],'123456','02')
WHERE [CustomerID] = 4

this code replace 02 on 123456 but i want to change on 2 first digit is change to 023456 can any one help me Thank

2

There are 2 best solutions below

0
Mihai On
UPDATE [Customers] 
SET [Address] = REPLACE([Address],'12','02')
WHERE [CustomerID] = 4

Assuming 12 don't repeat in the string.

0
Chintan On

Why do you put only '02' characters instead of '023456'? Are you having some situation where you have to put only first two characters, if not try following.

UPDATE [Customers] SET [Address] = REPLACE([Address],'123456','023456')
WHERE [CustomerID] = 4