Focal Point
[SOLVED] Joining to a table with effective dates/terms

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

January 07, 2019, 11:02 AM
CAWarner
[SOLVED] Joining to a table with effective dates/terms
I'm working on pulling information about faculty from a table that is organized with an effective term. Historically we have used MATCH FILE to get the relevant effective term, then MATCH FILE *again* using that retrieved term to collect the information from the relevant records. This is really getting out of hand both in terms of resources consumed and the difficulty in maintaining and updating the reports that use this method for multiple effective-term tables.

I have begun using conditional joins to simplify many of our existing reports, but I can't figure out how to ensure that a join will pick up the correct record. Here is what I am envisioning, field and file names altered for readability:

JOIN LEFT_OUTER
FILE FACULTYASSIGNMENTS	AT FACULTYASSIGNMENTS_ID	TAG ASG 	TO ONE
FILE FACULTYDETAIL	AT FACULTYDETAIL_ID		TAG DET 	AS JFDE
WHERE ASG.FACULTYASSIGNMENTS_ID EQ DET.FACULTYDETAIL_ID;
WHERE DET.FACULTYDETAIL_EFFECTIVETERM LE &CURRENT_TERM;
WHERE DET.FACULTYDETAIL_EFFECTIVETERM {***IS THE HIGHEST OF THE AVAILABLE RECORDS***};
END


What can I do to get a join to identify the record with the highest effective term?

I have found this example SQL code that accomplishes this task, but I'm unsure of how I would implement it in a FOCUS join (different field names taken directly from example):

WHERE NOT EXISTS
(
    SELECT *
    FROM Vat_Rate_Details VRD2
    WHERE
        VRD2.rate_id = VR.rate_id AND
        VRD2.effect_date < NOW() AND
        VRD2.effect_date > VRD1.effect_date
)

This message has been edited. Last edited by: FP Mod Chuck,


WebFOCUS 8202
Windows, All Outputs
January 07, 2019, 11:23 AM
MartinY
If you already have the code in SQL, you can use "SQL pass through" : several post and doc on the subject.

Or you may have to first extract the "highest of the available records" to have them used in your JOIN as a joined file
Or extract the highest date, set a variable to this value and use this new variable in your WHERE clause
Or ...

Many other option may exist but difficult to tell since we don't know how your data is organized and their relationship.


WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
January 07, 2019, 07:47 PM
TobyMills
+1 for
Or extract the highest date, set a variable to this value and use this new variable in your WHERE clause

I presume you have a table you can hit where you can retrieve a single row with the value of the start of the effective term. if you need to grab the ending date at the same time, do that so they end up in one row (2 columns).

Then -READ the dates into a & variables so you can use the &STARTEFFDATE and &ENDEFFDATE in your code.

If you find that you need this date range often, I would put this in it's own focexec so you can -INCLUDE it anytime to create those two dates for you. If you use it VERY often, you might even decide to go with && global variables set from EDASPROF so that those variables are always available to all procedures.

Good luck!
Toby Mills, CISSP
January 08, 2019, 10:27 AM
CAWarner
quote:
Originally posted by MartinY:
Or you may have to first extract the "highest of the available records" to have them used in your JOIN as a joined file


Okay, this gave me ideas. I can use a MATCH to look up the most recent effective term in FACULTYDETAIL for each person in my query without including any of the other information I'll be reporting on. That keeps my runtime short. I can then JOIN to the hold file I just created to use those effective terms (unique for each individual - each person gets a new effective term when the terms of their employment change) in my JOIN to FACULTYDETAIL to get the rest of the relevant information.

I would still prefer to avoid using a MATCH to do this, but I've at least significantly improved the performance of this report. This change also improves the legibility of the code.

Thank you for the suggestion!


WebFOCUS 8202
Windows, All Outputs
January 08, 2019, 12:09 PM
MartinY
quote:
I can use a MATCH to look up the most recent effective term in FACULTYDETAIL for each person

Why the needs to use MATCH ?

Can you not just use something such as
TABLE FILE FACULTYDETAIL
SUM MAX.EFFECTIVETERM
BY PERSON
ON TABLE HOLD AS MAXEFF FORMAT FOCUS INDEX PERSON
END
-RUN

Then use MAXEFF file in the JOIN


WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
January 08, 2019, 12:42 PM
CAWarner
quote:
Why the needs to use MATCH ?


You're right. This table is not so large that I'm saving any effort trying to query only a subset of it. I could do what you say here and produce a hold file that simply indexes the appropriate EFF_TERM for everyone. This would work on nearly every table I work with. Only 1 or 2 of our tables are so bloated that I would want to limit it to relevant people.

Thanks a million!


WebFOCUS 8202
Windows, All Outputs
January 08, 2019, 04:34 PM
MathematicalRob
Another option is to join LIMITING_TABLE and EFFECTIVE_TERM_TABLE, and then

PRINT FIELDS FROM JOIN
BY HIGHEST 1 EFFECTIVE_TERM
WHERE EFFECTIVE_TERM LE CURRENT_TERM


- Rob


WebFocus 8201m on Windows; App Studio 8201; Procedures: WebFocus with SQL; HTML Parameter Pages & Dashboard; Output: Excel, HTML, & PDF.