Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Import and Export of Data function in sql

Author  Topic 

divan
Posting Yak Master

153 Posts

Posted - 2012-08-16 : 09:16:31
I am trying to create a table in sql using the import and export data function in sql.. my input file is a xls file and the first column is a a 3 character code the codes that start with a 0 (eg 010, 015, 020) get imported correctly but then the codes that start with anything but 0 are imported as a NULL.

column in xls

OPCO_CODE
005
020
025
100
105
110
115

code in sql
005
020
025
NULL
NULL
NULL
NULL
NULL

any idea

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-16 : 09:49:06
This usually happens if you have a column that is numeric in the initial few rows and have non-numeric values in the later rows. Import Wizard samples the first few rows and decides that it is a numeric data type and goes on with the import, but then when it runs into non-numeric data, it throws up its hands and the table ends up getting nulls.

In your cases, that does not seem to be the case - in fact it seems to be the opposite.

Do you have any non-numeric data in that column? If so, in the import/export wizard, in one of the screens in the wizard, there is an Edit Mappings button - click that and make sure the column is designated as character type.

What is the data type of the column in the destination table? If it is numeric, then you cannot have non-numeric data in the excel file.

Not very precise answers, are they? I am just guessing here :)
Go to Top of Page

divan
Posting Yak Master

153 Posts

Posted - 2012-08-16 : 09:58:43
SUNITABECK If I was a gambling man I would hire you to be my advisor.. Your guessing here was very accurate....
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-16 : 11:28:23
Ha! It just so happens that I am looking for a position as an adviser to gamblers. :)

Just kidding! Glad you got it figured out!!
Go to Top of Page
   

- Advertisement -