Solved

exporting ssn to sql server

Posted on 2013-01-08
15
309 Views
Last Modified: 2013-01-09
The format in excel has a special SSN format, however when I import it ot SQL , it removes all the "-"  eg.xxx-xx-xxx and also if SSN  begins with 0, it gets truncated and lose that digit.
What is the technique to import SSN without losing the "-" in the process?
0
Comment
Question by:zachvaldez
  • 7
  • 3
  • 2
  • +2
15 Comments
 
LVL 69

Expert Comment

by:ScottPletcher
Comment Utility
Don't know if you can retain the "-"s or not.

But you can prevent the leading 0s from being removed by defining the column as varchar() rather than numeric for the transfer.
0
 

Author Comment

by:zachvaldez
Comment Utility
if so, what is the update formula  for the column if it gets imported as
'xxxxxxxxx' so it would convert to 'xxx-xx-xxxx'

and if it loses 0 in the beginning adds '0'.. thanks
0
 
LVL 31

Expert Comment

by:awking00
Comment Utility
select substr(lpad(ssn,9,'0'),1,3)||'-'||substr(lpad(ssn,9,'0'),4,2)||'-'||substr(lpad(ssn,9,'0'),6)
0
 
LVL 69

Assisted Solution

by:ScottPletcher
ScottPletcher earned 100 total points
Comment Utility
Immediately after any import, you could run UPDATEs, like this:


UPDATE dbo.tablename
SET ssn_column = RIGHT(REPLICATE('0', 9) + ssn_column, 9)
WHERE
    LEN(ssn_column) < 9

UPDATE dbo.tablename
SET ssn_column = LEFT(ssn_column, 3) + '-' + SUBSTRING(ssn_column, 4, 2) + '-' + SUBSTRING(ssn_column, 6, 100)
WHERE
    ssn_column NOT LIKE '___[-]__[-]____%'
0
 
LVL 31

Expert Comment

by:awking00
Comment Utility
Sorry, was thinking Oracle syntax instead of sql server where right(replicate(... replaces lpad and substring replaces substr and + replaces ||. ScottPletcher has your answer.
0
 

Author Comment

by:zachvaldez
Comment Utility
Im getting error saying Replicate function requires 2 argument(s)
0
 
LVL 69

Expert Comment

by:ScottPletcher
Comment Utility
Hmm, something's not coded right then, because the REPLICATE part above:

select
REPLICATE('0', 9)

select
RIGHT(REPLICATE('0', 9) + ssn_column, 9)
from (
    select '123456' as ssn_column
) as test_data
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:zachvaldez
Comment Utility
Ok I found my mistake. thanks. It only corrected a few. I think its possible that an SSN could start with '00',000'..
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 150 total points
Comment Utility
When you apply a number format to a true number in Excel, it is the actual value and not the displayed value that gets stored.

The easiest way to approach this, in my opinion, would have been to add a column in your Excel worksheet, and use a formula to explicitly convert the SSN to a text value, such as:

=TEXT(A2,"000-00-0000")

That will preserve the dashes, as well as any leading zeroes as needed.
0
 

Author Comment

by:zachvaldez
Comment Utility
What data type should I set the new column in sql server. when I imported it , they were all Null even though they have the correct format 'xxx-xx-xxxx' afte using
=text(a2,"000-00-0000")
0
 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
You would have to use a data type that supports text.

At the very least you would want [n][var]char(11), depending on whether you want ANSI or Unicode, and whether you want fixed or dynamic length.

If there is any possibility that you will be storing other items in that column (such as a business tax ID number), you may want to specify a longer length.
0
 

Author Comment

by:zachvaldez
Comment Utility
Thanks,Igot it!!
0
 
LVL 21

Assisted Solution

by:Alpesh Patel
Alpesh Patel earned 70 total points
Comment Utility
Just convert the Field to Text in Excel and Import it using Wizard.
0
 

Author Comment

by:zachvaldez
Comment Utility
I didn't think. Yeah,that probably the simplest solution
0
 

Author Closing Comment

by:zachvaldez
Comment Utility
iT WORKED!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now