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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case in a join

Status
Not open for further replies.

munchen

Technical User
Aug 24, 2004
306
GB
Is there a way to something like this in a join?

case
when a.refno is null then b.refno > tmp.refno
else
a.refno > b.refno

I need this to be in the join. Can this be done?

Thanks in advance
 
how about
inner join tablename a
on isnull(arefno,tmp.refno)>b.refno
 
sorry SB

Code:
inner join tablename a
on isnull(a.refno,tmp.refno)>b.refno
 
pwise

thanks for your response. that's not what i'm after as:

case
when a.refno is null then b.refno > tmp.refno
else
a.refno > b.refno

If a.refno is null then I want b.refno to be greater than tmp.refno. If a.refno is not null then I want a.refno to be greater than b.refno whereas the code you supplied ALWAYS has either a.refno or tmp.refno to be greater than b.refno.

Does that make sense?

 
Try
Code:
Case when a.refno is null then b.refno else a.refno end 
>
Case when a.refno is null then tmp.refno else b.refno end [code]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top