473,387 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Phone # question

I assume a SS# or Phone# should be either a varchar or char field. But
is it a good idea to store a phone# or SS# w/ seperator characters or
without them?

Phone# "(123)-456-7890" or "1234567890"

SS# "123-45-6789" or "123456789"

I'm not sure which is better. Any opinions? Also has anyone had a
situation where a phone# could have an extension? How was it handled?
Seperate field or just one?

Any input appreciated. Thanks.

Aug 9 '05 #1
6 1128
(wa********@yahoo.com) writes:
I assume a SS# or Phone# should be either a varchar or char field. But
is it a good idea to store a phone# or SS# w/ seperator characters or
without them?

Phone# "(123)-456-7890" or "1234567890"

SS# "123-45-6789" or "123456789"

I'm not sure which is better. Any opinions? Also has anyone had a
situation where a phone# could have an extension? How was it handled?
Seperate field or just one?


For Phone numbers I would recommend delimiters, or else a number
like +46-8-90510 will be mangled.

For social-security numbers it's a little different. We store them
without delimiters, but I wonder what we would do if would had to
handle numbers like the above. Then again, we already store the
country code associated with SSN, so maybe it would not be a problem.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Aug 9 '05 #2
>> SS# or Phone# should be either a varchar or char field [sic] <<

Try use CHAR(n) instead of VARCHAR(n) instead. I like removing the
delimiters IF the format is fixed. If the data can have various
formats, then use a horrible constraint:

CREATE TABLE Foobar
( ..
x CHAR(3) DEFAULT ('XXX') NOT NULL
CHECK (CASE WHEN x LIKE 'AB[0-9]' THEN 'T'
WHEN x LIKE 'XY[0-9]' THEN 'T'
\\ ELSE 0 END = 'T'

Aug 10 '05 #3
Stu
I agree with Erland; I would let the application validate the phone
number and enter them with delimiters into your database, mainly
because of issues with international numbers and extensions. We
typically enter phone + extension into a single column in our database
structure, and extract the partial phone # (if necessary) on the client
side.

HTH,
Stu

Aug 10 '05 #4
The constraint is horrible, that's for sure. It
raises an error trying to convert 'T' to a number,
since the CASE expression will be typed as an integer
or numeric.

What integer did 'T' convert to on the system
you used to test the code?
If you need a constraint like this, write it so
it can be understood, and so that it doesn't
generate an error:

CHECK (x LIKE 'AB[0-9]' OR x LIKE 'XY[0-9]')

Steve Kass
Drew University
--CELKO-- wrote:
SS# or Phone# should be either a varchar or char field [sic] <<

Try use CHAR(n) instead of VARCHAR(n) instead. I like removing the
delimiters IF the format is fixed. If the data can have various
formats, then use a horrible constraint:

CREATE TABLE Foobar
( ..
x CHAR(3) DEFAULT ('XXX') NOT NULL
CHECK (CASE WHEN x LIKE 'AB[0-9]' THEN 'T'
WHEN x LIKE 'XY[0-9]' THEN 'T'
\\ ELSE 0 END = 'T'

.

Aug 10 '05 #5
On 9 Aug 2005 19:49:11 -0700, --CELKO-- wrote:

(snip)
x CHAR(3) DEFAULT ('XXX') NOT NULL
CHECK (CASE WHEN x LIKE 'AB[0-9]' THEN 'T'
WHEN x LIKE 'XY[0-9]' THEN 'T'
\\ ELSE 0 END = 'T'


Hi Joe,

Apart from Steve's comments, I'm also curious why you supply a default
that won't pass the CHECK constraint. If you want an error if no value
is supplied, then why not simply remove the DEFAULT? Gives me an error
message that is much easier to debug!

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Aug 10 '05 #6
Thanks for the input guys. Delimeters it will be then I think.
I appreciate your thoughts, thanks again.

Aug 10 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: joemono | last post by:
Hello everyone! First, I appologize if this posting isn't proper "netiquette" for this group. I've been working with perl for almost 2 years now. However, my regular expression knowledge is...
4
by: William Morris | last post by:
Our application tracks contact information. One of our clients, a car dealership, has asked about being able to enter a lastname and phone number and getting as much of the main form filled out as...
3
by: Sara | last post by:
HI, I want to code a program to detect GSM mobile (any kind) which connected through serial port to computer and then be able to send SMS through this mobile phone to other mobile phones, could...
2
by: Peter | last post by:
I hate using the mask edit conrol so I created these two function to format my phone numbers. Is there a way to consolidate these two functions into one? In this example say the textbox you...
7
by: MuZZy | last post by:
Hi, We are developing a CRM (Customer Relations Management) module for our app and my boss wants to provide integration with PBX (phone systems used by lots of companies) so that if a user gets...
4
by: kron | last post by:
I wish call VOIP phone number (know this part) and connect/receive signals (inser/show data from database) from web server over VOP phone number? is it possible?
9
by: Alex | last post by:
Get the Name and Phone Number of the Current Windows User in a .NET Application I am writing a simple .NET (C#) application. It needs to "automatic" get the Name (last, first) and phone number...
4
by: Blue Streak | last post by:
Hello, Folks! Does anyone know of a website that lists the local phone number formats for each country? TIA...
1
by: =?Utf-8?B?bW9uaWNhX2ZyYXppZXI=?= | last post by:
When I import contacts from excel using the import wizard, even after matching fields to field for some reason I can only get the first three to five from my list of 190 to import the phone numbers...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.