Problem w/ Nulls:  Import Excel 2002 -> SQL Server 2000

Posted on 2003-10-23
Last Modified: 2007-12-19
I am attempting to import 6 worksheets from Excel to 6 tables in SQL Server 2000.  When the package executes, I get the following error message:

"Error during Transformation 'DirectCopyXform' for Row number 801.  Errors encountered so far in this task:  1. TransformCopy 'DirectCopyXform' conversion error:  Destination does not allow NULL on column pair1 (source: column 'my_col_name' (DBTYPE_R8), destination column 'my_dest_col' (DBTYPEI8))."

This is strange because my excel spreadsheet has only 800 rows, and none of them are null.  Is it possible that SQL Server is reading in my spreadsheet and is running right off the end of my data?  

In an attempt to understand what was going on, I created a test environment with an identical destination table that allowed nulls in my_dest_col.  With this, I was able to import successfully, but I got 2 null rows in my database for some (possibly all) tables.

One possible workaround is temporarily allowing nulls in the database in my production environment (while I import the data).  Then I could delete the erroneously imported null values and uncheck the box to allow nulls in enterprise manager.  Is it possible that this solution would cause damage to my database?  It's not under constant pounding, but a few people might fill out submission forms in that interval.

Comments by mid-morning 10/24 EST would be greatly appreciated since I'll probably try the import in production at that time.
Question by:Igiwwa
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 75

Expert Comment

by:Anthony Perkins
ID: 9610987
>>Is it possible that SQL Server is reading in my spreadsheet and is running right off the end of my data? <<
Correct.  Delete the "blank" rows at the end and your problem will go away.

>>One possible workaround is temporarily allowing nulls in the database in my production environment (while I import the data). <<
You should never import directly into a table (let alone in Production), but rather you should import into a temporary table first and then select the appropriate rows into the final table.  This way you can verify what is actually going in (remember the old adage: "garbage in, garbage out").


Author Comment

ID: 9611062
I already tried to delete these "blank" rows and it didn't seem to make any difference.  I guess that's because Excel always gives you infinite empty rows and columns.  Is there any way I can make the spreadsheet just end after row 800?  Maybe I can use MS Access (*shudder*) as an intermediary.

Thanks for the tip about the temporary table, I will definitely use that regardless of the outcome of this problem.
LVL 75

Accepted Solution

Anthony Perkins earned 450 total points
ID: 9611093
>>I already tried to delete these "blank" rows and it didn't seem to make any difference. <<
I suspect it depends how you are deleting them.

In any case, when you import it in, use a query instead of a straight copy, as in:

Select *
From [Sheet1$]
Where Not [Column1] Is Null

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

LVL 15

Expert Comment

ID: 9613365
I have not had any issues DTS from Excel to MS SQL Server. But I often use a funcky way to import data from excel to MS SQL Server.

For Example, say I have data listed below in a spreadsheet
Col1  Col2   Col2       Col4
1       A       XXXX    
2       B       YYYY

For Col4, I use excel function CANCATENATE to come up with a sql statement concatenating values in the other columns

=CONCATENATE( " INSERT INTO MYTBALE (COL1, COL2, COl3) VALUES (", A1, ",'", B1, "','", C1,"')" )

Then copy the column 4 data to Query explorer and execute it. The data is imported.

You may want to use this method if nothing helps.

LVL 30

Expert Comment

ID: 9613614
If Excel is too dumb to work out where the data stops, you can select all the data and make it a named range (type a name into the cell drop down in the bottom left of the toolbar)

Then I think it is possible to tell DTS to only import the named range.

It's a bit impractical for a automted system though.

Author Comment

ID: 9616870
I like acperkins suggestion:

Select *
From [Sheet1$]
Where Not [Column1] Is Null

It seems to work well in a test environment.  I was going to try it for real later today, but other stuff has come up so it may have to wait until next week, but it looks quite promising.

LVL 34

Expert Comment

ID: 9623520
I agree with acperkins suggestion in every way.  Not only can you use the query to extract only the records you need, but you REALLY SHOULD use the temp table--makes it easier to "clean" any data ahead of time, and also makes it easier to back out data if you have a problem.....


Author Comment

ID: 9627548
Ok.  I did the import and everything worked well.  There is just one small problem.  I have a unique id for each record.  Before the import I was in the mid 5000s.  To be able to easily identify the newly imported records, I started them at 10,000.  Now the auto numbering of sql is starting new records in the 10,000 block.  Is there any way I can make it start giving out ids in the 5000s again?
LVL 75

Expert Comment

by:Anthony Perkins
ID: 9628881
You cannot reassign the IDENTITY column to a lower number than already exists.  If this is not the case checkout the command:

From BOL:
Checks the current identity value for the specified table and, if needed, corrects the identity value.

    ( 'table_name'
        [ , { NORESEED
                | { RESEED [ , new_reseed_value ] }



Author Comment

ID: 9630409
Thanks a lot everyone!

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

705 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