kevinkhan Posted September 30, 2016 Share Posted September 30, 2016 i have alot of numbers with 10 digits like this0987654321I want a sql query that will remove the 0 and add 353.Is there any body that can help me with this please? Quote Link to comment https://forums.phpfreaks.com/topic/302260-regex-remove-0-and-add-country-code/ Share on other sites More sharing options...
Barand Posted September 30, 2016 Share Posted September 30, 2016 this doesn't use regex but mysql> SELECT id -> , name -> , phone -> , CASE -> WHEN SUBSTRING(phone,1,1)='0' -> THEN CONCAT('(353)',SUBSTRING(phone,2)) -> ELSE phone -> END as phone2 -> FROM contact; +----+-------------+-------------+-----------------+ | id | name | phone | phone2 | +----+-------------+-------------+-----------------+ | 1 | aaaaaaaaa | 12345674321 | 12345674321 | | 2 | bbbbbbbb | NULL | NULL | | 3 | cccccccc | 01214567890 | (353)1214567890 | | 4 | dddddd | NULL | NULL | | 5 | eeeeeeeeeee | 09087654321 | (353)9087654321 | | 6 | kkkkkkkkk | NULL | NULL | | 7 | mmmm | NULL | NULL | +----+-------------+-------------+-----------------+ 1 Quote Link to comment https://forums.phpfreaks.com/topic/302260-regex-remove-0-and-add-country-code/#findComment-1537925 Share on other sites More sharing options...
PravinS Posted October 12, 2016 Share Posted October 12, 2016 You can use UPDATE query like this UPDATE table_name SET phone = CONCAT('353',TRIM(LEADING '0' FROM phone)) WHERE SUBSTRING(phone,1,1) = '0'; before that use the SELECT query to check if its correct or not SELECT phone, CONCAT('353',TRIM(LEADING '0' FROM phone)) FROM table_name WHERE SUBSTRING(phone,1,1) = '0'; hope this will find you helpful Quote Link to comment https://forums.phpfreaks.com/topic/302260-regex-remove-0-and-add-country-code/#findComment-1538216 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.