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 2005 Forums
 Transact-SQL (2005)
 Display duplicates from external list

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 s
LEFT JOIN YourTable t
ON t.PK=s.PK
WHERE t.PK IS NULL


Go to Top of Page

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 s
LEFT JOIN YourTable t
ON t.PK=s.PK
WHERE t.PK IS NULL





wouldn't intersect be more appropriate?

select column
from newtable
intersect
select column
from existingtable
Go to Top of Page

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 s
LEFT JOIN YourTable t
ON t.PK=s.PK
WHERE t.PK IS NULL





wouldn't intersect be more appropriate?

select column
from newtable
intersect
select column
from 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.
Go to Top of Page

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.
Go to Top of Page

lamaar75
Starting Member

2 Posts

Posted - 2008-09-16 : 04:47:22
thanks guys, much appreciated
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -