Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selection criteria from two different tables

Status
Not open for further replies.

simma

Programmer
Sep 11, 2001
398
US
Hello
I have 3 tables A,B,C linked by A.id
i need a query something like
select A.des,B.df_date,C.nxt_date,A.id
from A
inner join B
on A.id=B.id
inner join C
on A.id=C.id
where
(if A.des='P Sale' then B.df_date between '08/01/2002'and '08/31/2002'
elseif A.des='AFB' then C.nxt_date
between '08/01/2002'and '08/31/2002')
Please advice
Thanks

A.des B.df_date C. nxt_date A.ID
------------------------------ ---------------------------
P Sale 2002-04-15 2001-09-01 1
P Sale 2002-06-14 2001-07-01 2
P Sale 2002-06-17 2001-07-01 3
P Sale 2002-08-16 2001-02-01 5
AFB 2002-04-16 2002-04-01 6
AFB 2002-06-10 2002-02-01 9
AFB 2002-08-09 2002-09-01 7
 
The query Im trying to write is in SQL Server 7.0
Thanx
 
Try to join the tables this way:

Select A.des, B.df_date, C.nxt_date
from A, B, C
where
A.id= B.id and B.id = C.id and .... (your other criterias) Hope it helps

SC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top