November 30, 2006 at 12:21 pm
I am creating table & one of column name is phonenumber. the number will be inserted as (1234567890) in column but i want that while inserting it should insert like this (123-456-7890). any help is appreciated & thanking in advance.
November 30, 2006 at 12:41 pm
You're mixing data requirements with presentation requirements.
What if you fill your database with formatted phone number strings like this, and then the requirement for how the dta is presented changes in the future ?
November 30, 2006 at 2:32 pm
I agree with that! Store the phone number as a string of digits only... the other kludge that needs to be considered is are any international numbers ever going to be stored? Like PW said, don't store the formatting.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 30, 2006 at 11:00 pm
Or store it as an integer like the others suggested and then add a computed column that formats it in the format you want
Alter
Table MyTable Add FormattedPhone As Stuff(Stuff(PhoneNumber, 4, 0, '-'), 8, 0, '-')
November 30, 2006 at 11:21 pm
Same phone number will be dialed (that means appeared for the user) in different ways from different locations.
Unless you mean to limit usage of your application to a single town you need to store international, long distance codes and numbers itself separately and build it according to location of the user and predefined rules specified for this location.
_____________
Code for TallyGenerator
December 1, 2006 at 5:07 am
You'd have to store it as a BIGINT... most phone numbers are too big for just INT. That would also guarantee numerics only.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 1, 2006 at 7:51 am
It may be worth pointing out that if your number starts with a Zero (0), as in the UK, it needs to be stored as a varchar. I agree with the points above about not storing formatting though, and I'm especially impressed with Robert Davis's trick of
Stuff(Stuff(PhoneNumber, 4, 0, '-'), 8, 0, '-')
Dave
December 1, 2006 at 8:29 am
Thank you very much for your all response/replies. this helped me to decide right datatype & formating. thanks again
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply