Focal Point
DEFINE-based JOIN problem

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/1711038331

February 07, 2005, 04:25 PM
<Pietro De Santis>
DEFINE-based JOIN problem
According to the manual, the syntax for a normal JOIN is:

JOIN field1 [AND field1a...] IN host [TAG tag1]
TO [ALL] field2 [AND field2a...] IN crfile [TAG tag2] [AS joinname]
END

The syntax for a DEFINE-based JOIN is:

JOIN deffld WITH host_field IN hostfile [TAG tag1]
TO [ALL] cr_field IN crfile [TAG tag2] [AS joinname]
END

I would like to JOIN one DEFINEd field and one regular field from one Oracle table to two regular fields in another Oracle table.

The syntax I am using:

JOIN DEFFIELD1 WITH FIELD1 AND FIELD2 IN TABLE1
TO FIELD1 AND FIELD2 IN TABLE2 AS J1
END

I get the following error:

(FOC376) SYNTAX ERROR OR MISSING ELEMENT IN THE JOIN COMMAND

It appears I cannot JOIN a "virtual" field and a "real" field in one table to a "real" field and a "real" field in another table.

I need to join a P5 field and a A25 field to a A10 field and a A25 field in two Oracle tables.

Any ideas?

Thanks,

Pietro.
February 07, 2005, 04:54 PM
Leah
I wonder if it isn't the FIELD1 AND FIELD2 that is giving you the error.

JOIN DEFFIELD1 WITH FIELD1 AND FIELD2 IN TABLE1
TO FIELD1 AND FIELD2 IN TABLE2 AS J1
END

I get the following error:

(FOC376) SYNTAX ERROR OR MISSING ELEMENT IN THE JOIN COMMAND

I don't know as I ever got two fields to join in a defined based join. I know we even had issues getting it to work in Web 4.3.6
February 07, 2005, 06:03 PM
TexasStingray
Trick IT:

You can do this. Lets trick it. You can join on the 2 real fields and create your define field then add your own where statement for the other join. You can turn on SQL tracing and turn off retrieval execution to see the SQL by adding the below 3 line to the top of your focexec. NOTE: this trick only works for a SQL RDBMS and may not work for cross database joins.

SET TRACEON=STMTRACE//CLIENT
SET TRACEUSER=ON
SET XRETRIEVAL=OFF
February 07, 2005, 07:15 PM
<Pietro De Santis>
"You can join on the 2 real fields and create your define field then add your own where statement for the other join."

That sounds interesting - I may give it a try. Thanks.
February 07, 2005, 11:31 PM
j.gross
I assume use of WITH with a compound key is supported.

The WITH phrase doesn't really modify a particular key element -- it modifies the JOIN as a whole. "WITH wfld" specifies that the overall key for the join changes whenever a new instance of the segment containing wfld is read.

Thus the WITH phrase belongs after the list of key fields, and the WITH fieldname should be a field in the lowest segment that contributes to the overall key.

For example, if the first element of a two-piece key is a defined field based entirely on the root segment, but the second element of the compound key is in a lower segment,
JOIN fld1 AND fld2 WITH fld2
would be correct; WITH <some-field-in-the-root-segment> would yield incorrect results.

In your case, use:
JOIN DEFFIELD1 AND FIELD2
WITH FIELD1
IN TABLE1
TO FIELD1 AND FIELD2
IN TABLE2
AS J1
END
February 08, 2005, 02:47 PM
j.gross
quote:
Originally posted by Pietro De Santis:
[qb] . . .
I need to join a P5 field and a A25 field to a A10 field and a A25 field in two Oracle tables.
[/qb]
I assume the P5 is USAGE= P10, ACTUAL=P5.

Let's decompose the problem. There is a series of three challanges here:

1. For just the P5 to A10 equality test, can you express a single-key join as a SQL SELECT. It will depend on the functions supported by your RDBS for WHERE equality conditions (and on whether negative values can occur and how they are represented in the A10.)

2. Having composed a SELECT that satisfies (1), can the Focus interface to your RDBS be induced to generate such a SELECT to accomplish the single-key join? (If not, you're going to have to resort to SQL passthru.)

3. How to extend that to a two-key join: What's the Focus syntax for a define-based compound-key join?

Do you have you a solution in hand for #1?
February 08, 2005, 05:14 PM
Carol Dobson
When all else fails, I create hold files and concatenate my two fields into one for each file, then do the join on the concatenated fields.
Works like a charm!