Try a "left outer join"
select a.field1, b.rdItmVlu, c.rdItmVlu
from HeaderFile A
left outer join DetailFile B
on a.Key1 = B.Key1
AND b.RcdType = 'ABC'
AND b.rdItmVlu <> ' '
left outer join DetailFile C
on a.Key1 = c.Key1
AND c.RcdType = 'XYZ'
AND c.rdItmVlu <> ' '
From: Jack Prucha <Jack.Prucha@xxxxxxx>
To: "midrange-l@xxxxxxxxxxxx" <midrange-l@xxxxxxxxxxxx>
Date: 03/23/2016 01:15 PM
Subject: SQL Select This and/or That
Sent by: "MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxx>
I'm having a hard time visualizing how to do this. There's a "Header" and
"Detail" file where I want to return information from both whenever at
least one of these situations occur. What I've coded only returns if both
situations occur. This gets me most of what I want:
select a.field1, b.rdItmVlu, c.rdItmVlu from HeaderFile A, DetailFile B,
DetailFile C
WHERE a.Key1 = B.Key1
AND b.RcdType = 'ABC'
AND b.rdItmVlu <> ' '
AND a.Key1 = c.Key1
AND c.RcdType = 'XYZ'
AND c.rdItmVlu <> ' '
Selection should occur if either the ABC or XYZ record has the, well,
undesired values rather than my example which selects only if both records
meet the selection criteria. I know I can use the Coalesce to default the
rditmvlu for which ever record isn't there. But how can I "subselect" and
return the value back to the original select? Can't assume each record
type exists.
7.1 with all the TRs installed
Thanks in advance!
Jack Prucha
Programming Team Supervisor
College Foundation, Inc.
919.835.2530
This email, including any documents, files, or previous email messages
attached to it, has been sent from an email account of College Foundation
Inc., (CFI) and may contain confidential, proprietary, or legally
privileged information belonging to CFI. If you are not the intended
recipient, any dissemination, distribution, or copying of this email or its
attachments is strictly prohibited. If you have received this email in
error, please immediately notify the sender by email and destroy the
original email and any attachments.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
http://archive.midrange.com/midrange-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
As an Amazon Associate we earn from qualifying purchases.