I have a table name tariff, but now I want to replace values in column service_code
The values are like this:
D2P
D2D
D2D
D2P
D2D
What I want to achieve:
P2P
P2D
P2D
P2P
P2D
Just changing the 'D' to 'P' as first character
Use the below query:
UPDATE tariff SET service_code=CONCAT('P', SUBSTRING(service_code FROM 2))
where substring(service_code,1,1)='D';
or
UPDATE tariff SET service_code=CONCAT('P', SUBSTRING(service_code FROM 2))
where left(service_code,1)='D';
Use More Generic Query
update tariff set service_code='P'+substring(service_code,2,len(service_code)-1)
where substring(service_code,1,1)='D'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With