Link to home
Start Free TrialLog in
Avatar of mjburgard
mjburgardFlag for United States of America

asked on

Import from excel question

I am using an excel spreadsheet to import some data into a table in our sql database.  The issue is that the table contains a field that is a unique number that is generated for each contact address.  It is not used anywhere else in the database, but it is not nullable.  

I am using the import wizard to import this data - Is there a command I can add to the query it generates that will increment this number for every new entry the SQL import tries to insert?
Avatar of David Todd
David Todd
Flag of New Zealand image

Hi,

Is this number in the spreadsheet?

Is this number an identity column in SQL?

As a work around, import the spreadsheet into another table, and then copy the contents from this work table to the main one.

ie
insert dbo.MainTable( col2, col3, col4 )
select w.col2, w.col3, w.col4
from dbo.WorkTable w
left outer join dbo.MainTable m
    on m.SomeKeyCol = w.SomeKeyCol
where
    m.SomeKeyCol is null
;

HTH
  David
Avatar of mjburgard

ASKER

I will try the work around -
It is a number, however it is not a key, but it does appear in the Indexes folder of the table.
Hi,

I didn't ask if this was a key.

I asked if it was an identity column.

Regards
  David
Capture.PNG
Yes -
it is an identity column
ASKER CERTIFIED SOLUTION
Avatar of David Todd
David Todd
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This was what I needed to get the job finished.  There was a bit more that I needed to do, but this solved the issue I was having.