× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Thanks Mike
I am playing with the LEFT JOIN and it looks like its working
But I will keep in mind what you said

Alan Shore
E-mail : ASHORE@xxxxxxxx
Phone [O] : (631) 200-5019
Phone [C] : (631) 880-8640
'If you're going through hell, keep going.'
Winston Churchill


-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Mike Jones
Sent: Friday, June 30, 2017 3:08 PM
To: midrange-l@xxxxxxxxxxxx
Subject: Re: Using SQl to obtain a field value from one file or another

Hi Alan,

In addition to the LEFT JOIN advice you're getting, which is likely needed in your case, you may need or want to add something resembling this to the
mix:

select coalesce( nullif( FILE1.FIELD1, '' ), FILE2.FIELD1 ) as FIELD1
,coalesce( nullif( FILE1.FIELD2, '' ), FILE2.FIELD2 ) as FIELD2 from ...

Code like that delivers the first non-null, non-blank value found, from left to right.

The same result can be accomplished with a CASE expression, but I tend to prefer the above technique as it is less verbose.

I use code like that a lot in cases where a column is being delivered from more than one source column in the database, and a choice needs to be made to deliver the first non-blank column found. You could have two, or more, non-blank values to choose from, in which case the order in which you code the source columns will determine the results delivered.

Numeric columns would look like this:

select coalesce( nullif( FILE1.FIELD1, 0 ), FILE2.FIELD1 ) as FIELD1
,coalesce( nullif( FILE1.FIELD2, 0 ), FILE2.FIELD2 ) as FIELD2 from ...

Mike

From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Rob
Berendt
Sent: Friday, June 30, 2017 2:00 PM
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxx>
Subject: Re: Using SQl to obtain a field value from one file or
another

with T1 as (
select f1.field1, f2.field2 as col2
from f1 left inner join f2 on f1.field1 = f2.field1 union all select
f1.field1, f3.field2 as col2 from f1 left inner join f3 on f1.field1 =
f3.field2) select t1.field1, t1.col2 from t1 order by t1.field1

Rob Berendt
--
IBM Certified System Administrator - IBM i 6.1 Group Dekko Dept 1600
Mail
to: 2505 Dekko Drive
Garrett, IN 46738
Ship to: Dock 108
6928N 400E
Kendallville, IN 46755
http://www.dekko.com


--
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.

Help support midrange.com by shopping at amazon.com with our affiliate link: http://amzn.to/2dEadiD


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.