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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Trouble importing excel into db table (ID column)

Author  Topic 

jwood
Starting Member

1 Post

Posted - 2009-03-18 : 12:38:28
Dear Forum,
First of all, I would like to thank you for looking at my issue.
I am trying to import an excel file into a table in sql server 2000
The problem is, my Id column in the database does not allow nulls and It is not auto filling.
The columns in my excel file are: Pw, Sent, Downloaded
The Columns in my db table are: Id, Pw, Sent, downloaded

I am hoping to get the Id column in my table to autofill from 2 to 5000 as these rows are added. But it is giving me the error:
Error at Destination for Row number 199. Errors encountered so far in this task:1. The statement has been terminated. Cannot insert the value NULL into column 'Id', table 'simplestereo.dbo.songdload1';column does not allow nulls. INSERT fails.

I am using the DTS Import Export Data Wizard. When I click on the "Transform" button, and go to the "Column Mappings and Transformations" screen, it says that my Id column has no source and should be Ignored. What I would like to do is have that autofill the number incrimentally in the Id column in the database.
See Screenshot: http://www.iconconcerts.com/misc/columnmappings.jpg

Adding an Id column in my excel document with numbers 2 though 5000 would not work well because what if I want to import more rows later? It would be weird to make the second excel spreadsheet I import have an Id column that starts at 5001 and ends at 10,000.

So my question is, how do I make the database Id colum autonumber as it imports these in? Similar to how it autonumbers when I just do a simple Insert into the database.
Here is a screenshot of my table design: http://www.iconconcerts.com/misc/columndesign.jpg

I appreciate your help, or any advice you have.
Thanks
Jeff
Boise, ID

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-26 : 13:49:23
Your ID column is an identity column. So just uncheck enable identity insert in column mapping and transformation screen and you should be fine. To have ID column fill up from 2, you'll need to change the identity seed to 2 in table design screen.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-27 : 02:51:18
or enable identity and speicify the column names

insert into into table(Pw, Sent, downloaded)
select * from openrowset(...)

Refer
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -