|
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)
|
|
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)
|
|
Kev and Mukesh both have very good answers you may want to consider. The other option you may want to consider is writing a CLR in C#/VB.NET that uses regex to do what you want and then you can run that against the table from within SQL Server.
(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)
|
(comments are locked)
|
1 2 next page »

