SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 How to do lookup with pair of numbers
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mitasid
Yak Posting Veteran

New Zealand
51 Posts

Posted - 02/13/2013 :  13:50:40  Show Profile  Reply with Quote
Hi Guys
I have got two tables : one for the whole customer set adn the other table has got two columns- Id1 and Id2 and I am looking for those customers who have Id1 OR Id2

For ex
Cust table

Create table #Cust(cust_num int,ID int)
insert into #cust values(12,A1)
insert into #cust values(12,A2)
insert into #cust values(13,B1)
insert into #cust values(13,B2)
insert into #cust values(14,C1)
...

ID Table
Create table #ID(ID1 int,ID2 int)
insert into #ID values(A1,A2)
insert into #ID values(B1,B2)
insert into #ID values(Q1,"")
..

Now I want to design a query in such a way so that I get Customer nos who have either of two IDs in the ID table

Appreciate your help

Thanks
Mita


James K
Flowing Fount of Yak Knowledge

3636 Posts

Posted - 02/13/2013 :  14:26:32  Show Profile  Reply with Quote
SELECT 
cust_num,id -- or perhaps DISTINCT cust_num
FROM #Cust c
WHERE EXISTS (SELECT * FROM #ID i WHERE i.ID1=c.ID OR i.ID2=c.ID);
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000