Groups | Blog | Home
all groups > sql server new users > august 2005 >

sql server new users : modifying data?


_adrian
8/22/2005 5:26:37 PM
I have a column in a table full of phone numbers, except the user entered
them just as "a number" so (206) 555-1212 looks like 2065551212

Is there a way in which I can run something that will format all of these
with the appropriate parantheses, etc...? (ie. make them look like phone
numbers again)?

Brian Lawton
8/22/2005 9:16:35 PM
Assuming that your Phone attribute is a string and always contains 10
characters, you could use the following:

update table
set Phone = '(' + left(Phone, 3) + ') ' + substring(Phone, 4, 3) + '-' +
right(Phone, 4)

--
--Brian
(Please reply to the newsgroups only.)


[quoted text, click to view]

Raymond D'Anjou
8/23/2005 8:31:58 AM
To add to what Brian said, you could just leave them as they are in the
database and format them in the presentation layer.
But if you have some numbers with formatting and some without, it's better
to decide on how you want them in the database and to change the ones that
are not stored that way. I prefer to not include formatting and to do this
client side. It makes it easier when the boss decides that from now on, he
wants to change telephone number formatting from (206) 555-1212 to
206-555-1212.
Don't forget to validate future data entries.

[quoted text, click to view]

AddThis Social Bookmark Button