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
 General SQL Server Forums
 New to SQL Server Programming
 Check records

Author  Topic 

qutesanju
Posting Yak Master

193 Posts

Posted - 2010-07-22 : 02:49:22
I have records of emp id into a CSV file,this file contains records such as (5,15,19,17,............,n)

now I have to check all above records are present in
emp table or not

I know using below query I can find out easily but
I wanted to find is there any other ways of doing this
may be like EXIST clause

select * from emp
where empid in(5,12,19............,n)

Sachin.Nand

2937 Posts

Posted - 2010-07-22 : 03:26:11
select * from firstable t where exists(select 1 from secondtable t1 where t.empid=t1.empid)


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-22 : 03:26:22
Import the CSV into a table and then make a query.
-- look for empid's that are in CSV but not in emptable
select
c.empid
from CSV_Table c
left join emptable t
on t.empid = c.empid
where t.empid is null

If that is not what you want then please be more clear.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -