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.
| Author |
Topic |
|
lamaar75
Starting Member
2 Posts |
Posted - 2008-09-16 : 02:39:53
|
| I have extracted some information from Active Directory into an Excel spreadsheet. It only contains one field. I need to compare this list with a field in a SQL table and if it exists display the data, it doesn't have to be stored.Any help appreciated |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-16 : 03:03:41
|
Just dump the excel data onto a staging table and the use like below:-INSERT INTO YourTable(Field)SELECT s.Field FROm Staging sLEFT JOIN YourTable tON t.PK=s.PKWHERE t.PK IS NULL |
 |
|
|
mattyblah
Starting Member
49 Posts |
Posted - 2008-09-16 : 03:10:39
|
quote: Originally posted by visakh16 Just dump the excel data onto a staging table and the use like below:-INSERT INTO YourTable(Field)SELECT s.Field FROm Staging sLEFT JOIN YourTable tON t.PK=s.PKWHERE t.PK IS NULL
wouldn't intersect be more appropriate?select columnfrom newtableintersectselect columnfrom existingtable |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-16 : 03:16:46
|
quote: Originally posted by mattyblah
quote: Originally posted by visakh16 Just dump the excel data onto a staging table and the use like below:-INSERT INTO YourTable(Field)SELECT s.Field FROm Staging sLEFT JOIN YourTable tON t.PK=s.PKWHERE t.PK IS NULL
wouldn't intersect be more appropriate?select columnfrom newtableintersectselect columnfrom existingtable
What i got from OPs post was to insert only those records into table from excel which is not already present. Intersect will returns only records existing on both table and excel so i dont think it will serve the purpose. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-16 : 03:17:53
|
| I just read through post again. I think for display part you need the intersect however for storage part you need the code i posted. |
 |
|
|
lamaar75
Starting Member
2 Posts |
Posted - 2008-09-16 : 04:47:22
|
| thanks guys, much appreciated |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-16 : 04:53:08
|
quote: Originally posted by lamaar75 thanks guys, much appreciated
welcome |
 |
|
|
|
|
|