Solved

Import from excel question

Posted on 2014-01-30
6
188 Views
Last Modified: 2014-02-11
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?
0
Comment
Question by:mjburgard
  • 3
  • 3
6 Comments
 
LVL 35

Expert Comment

by:David Todd
ID: 39822034
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
0
 
LVL 1

Author Comment

by:mjburgard
ID: 39822267
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.
0
 
LVL 35

Expert Comment

by:David Todd
ID: 39822677
Hi,

I didn't ask if this was a key.

I asked if it was an identity column.

Regards
  David
Capture.PNG
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 1

Author Comment

by:mjburgard
ID: 39822766
Yes -
it is an identity column
0
 
LVL 35

Accepted Solution

by:
David Todd earned 500 total points
ID: 39822890
Hi,

Because it is an identity column, you can't (normally) specify a value for that.

So if the destination table looks like this
Create table dbo.MyTable(
    MyTableID int identity( 1, 1 )
    , SomeKey int
    , SomeOtherColumns varchar( 200 )
)

Then your insert needs to look something like this
insert dbo.MyTable( SomeKey, SomeOtherColumns )
select
    w.SomeKey
    , w.SomeColumns
from dbo.WorkTable w
left outer join dbo.MyTable m
    on m.SomeKey = w.SomeKey
where
    m.SomeKey is null
;

HTH
  David
0
 
LVL 1

Author Closing Comment

by:mjburgard
ID: 39850245
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.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

919 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

21 Experts available now in Live!

Get 1:1 Help Now