Defining a Default Storage Format for Phone# and SSN

  • When definining a Phone Number or SSN Field, what is the best way to provide a default format for these fields. For example, when a Phone Number is entered I want it to be stored as 804-303-2467 and when a SSN number is entered I want it to be stored as 111-22-3333. What is the best method to do this in SQL Server (SQL Server 2000, SP3).

    Thanks in advance, Kevin

     

  • Probably just as a varchar(xx) datatype.



    A.J.
    DBA with an attitude

  • AJ is correct, but are you looking to store the dashs?  If you are and you want to enforce it to always be the same, you'll need to manage user input in the application (ie no parentheses, periods, etc) and then simply concatenate the hyphens where needed within your proc with something like

    left(@Phone,3) + '-' + left(right(@Phone,3),6) + '-' + right(@Phone,4)

    Don't know if that's overkill or what you were looking for.  Hope it helps.

     

    If the phone doesn't ring...It's me.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply