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

Joining to a different field if one is blank

Status
Not open for further replies.

knacath

Programmer
May 22, 2001
8
US
Hi folks,

I've run into an interesting problem. I've 2 tables, Table1 & Table2. Table1.A needs a join to Table2.C. However, if Table1.A is blank (empty string, not null), it is Table1.B that needs to go out to Table2.C I'm using DB2/AS400. Any ideas?? Thanks.
 
You could try
[tt]
SELECT
*
FROM
Table1,
Table2
WHERE
Table1.A = Table2.C AND
Table1.A != ''
UNION SELECT
*
FROM
Table1,
Table2
WHERE
Table1.B = Table2.C AND
Table1.A = '';
[/tt]
That should give you the results you are looking for.


Tone
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top