|
Hi all, Can anyone help me with a little problem I can't solve. I am trying to update a phone_number column to replace any character that is not 0-9 with an empty string ie: PHONE_TABLE phone_number 01234-567-890 (result i want = 01234567890) 012345 6789ext (result i want = 0123456789) n/a (result i want = ) ...12345..... (result i want = 12345) i can identify which records have have non-numeric values in the phone number using...
but I want to update this table and remove non-numeric characters in the phone_number field something along the lines of....
Any help would be greatly appreciated Many thanks, Paul
(comments are locked)
|
|
OK just for fun, here's a TSQL method, using Jeff Moden's Tally table, and a SQL2005 (and later) trick for concatenating the results back
gives +1 - Nice. I was trying to think how a tally table could get involved but didnt have enough time to sit down and work on it. Thanks.
Mar 31 '10 at 04:43 AM
Fatherjack ♦♦
Cheers, although it needs some serious tuning if it was to be used for real....
Mar 31 '10 at 04:55 AM
Kev Riley ♦♦
(comments are locked)
|
(comments are locked)
|
|
Why not? Select (Replace(Replace(phone_number, '-', ''), ' ', '') from phone_table That would only replace the '-' and ' ' characters. The original question was to replace all non-numerics.
Jun 06 '12 at 10:22 PM
Kev Riley ♦♦
(comments are locked)
|
|
Do you have a lot of different non-numeric characters? If not I would simply go for
if there are lots of different ones and you need to repeat this process regularly then you might need to get involved with regex, functions and even clr ... Hi, yes I have lots of non-numeric characters in there from a-z and/or special characters....and about 650000 records....unfortunately they are all coming in from a dataload so i wanted to do a cleanup exercise. thanks for your help though, i have no idea where to start with regex etc.
Mar 30 '10 at 12:22 PM
Paul 3
(comments are locked)
|
U can Past above code in function and call function in select statment
Mar 31 '10 at 06:38 AM
Srikant Maurya
(comments are locked)
|
1 2 next page »

