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 2012 Forums
 Transact-SQL (2012)
 How to do lookup with pair of numbers

Author  Topic 

mitasid
Yak Posting Veteran

51 Posts

Posted - 2013-02-13 : 13:50:40
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
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-02-13 : 14:26:32
[code]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);
[/code]
Go to Top of Page
   

- Advertisement -