Solved

Import from excel question

Posted on 2014-01-30
6
194 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
[X]
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
  • 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

695 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