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.
Author |
Topic |
mitasid
Yak Posting Veteran
51 Posts |
Posted - 2013-02-13 : 13:50:40
|
Hi GuysI 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 Id2For exCust tableCreate 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 TableCreate 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 tableAppreciate your helpThanksMita |
|
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_numFROM #Cust cWHERE EXISTS (SELECT * FROM #ID i WHERE i.ID1=c.ID OR i.ID2=c.ID);[/code] |
|
|
|
|
|