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 2000 Forums
 Transact-SQL (2000)
 Mass verification of data in SQL

Author  Topic 

vinay.a
Starting Member

20 Posts

Posted - 2008-04-22 : 08:29:30
Hi all,

I need some help in doing mass verification of data.
I am uploading an excel sheet into a dataset, from there into a temporary table.

Problem:
I need to cross verify the temporary table against its original table to find out if there is any duplicate entry in the temporary table.
By the way, the verification is to be done on the id column which is a primary key.
If an id in the temporary table, exists in the original table, then I need to return such entries.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-22 : 08:59:56

select * from #temp t where exists(select * from main_table where id=t.id)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

tosscrosby
Aged Yak Warrior

676 Posts

Posted - 2008-04-22 : 15:51:40
If you can post your DDL, some sample data and any attempt at a query, I'm sure we can help. Not a whole lot to go on so far.......

Terry
Go to Top of Page

vinay.a
Starting Member

20 Posts

Posted - 2008-04-23 : 00:20:22
hi,

thanks for the reply.
I was going through a text book on sql-queries, and I found that the 'INTERSECT' and 'UNION' are good in doing the comparing task.

Please advice if the following sql-query is the fastest way to do comparison:
----------------------------------
SELECT * FROM tbl_temporary
WHERE SomeId IN (
SELECT SomeId FROM tbl_original
INTERSECT
SELECT SomeId FROM tbl_temporary)
----------------------------------
Here SomeId is the primary key field.
The above query would return the duplicate entries in the tbl_temporary table.

regards,
vinay
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-23 : 02:26:11
You could simply take a join with main table to verify this

SELECT * FROM tbl_temporary t
INNER JOIN tbl_original o
ON o.SomeId=t.SomeId
Go to Top of Page

vinay.a
Starting Member

20 Posts

Posted - 2008-04-23 : 02:42:12
thanks,

But tell me one thing which of them is faster, because I will be comparing between thousands of records.
Go to Top of Page

vinay.a
Starting Member

20 Posts

Posted - 2008-04-23 : 02:57:51
hi, can you please tell me how you came across my question.
I would like to know this, as I am new to this site.
How would I pick a question to answer.
Go to Top of Page
   

- Advertisement -