CharlesCook
Programmer
I have a table that containes multiple records for each person's benefit plans. Each plan has a effective date and effective squence. So a employee could have several records for the same benefit each with a different EFFDT and EFFSEQ combo.
The columns are as follows:
EMPLID
EMPL_RCD_NBR
EFFDT
EFFSEQ
BENEFIT_PROGRAM
A user wants to see the current benefit and current -1 benefit. To get the current benefit they are using a correlated subquery shown below in their where clause.
("PV_BEN_PROG_VW2"."EFFSEQ" = (
SELECT MAX("INNERALIAS"."EFFSEQ")
FROM "SYSADM"."PV_BEN_PROG_VW" INNERALIAS
WHERE "INNERALIAS"."EMPLID" = "PV_BEN_PROG_VW2"."EMPLID"
AND "INNERALIAS"."EFFDT" = "PV_BEN_PROG_VW2"."EFFDT")
AND
"PV_BEN_PROG_VW2"."EFFDT" = (
SELECT MAX("INNERALIAS"."EFFDT")
FROM "SYSADM"."PV_BEN_PROG_VW" INNERALIAS
WHERE "INNERALIAS"."EMPLID" = "PV_BEN_PROG_VW2"."EMPLID"))
To get the curent benefit -1 using a sub query in a sub query would get very messy. Is there a better way with newer SQL techniques?
Thanks
CharlesCook.com
ADP - PeopleSoft - SAP
ReportSmith - Crystal Reports - SQR - Query - Access
Reporting - Interfaces - Data Mining
The columns are as follows:
EMPLID
EMPL_RCD_NBR
EFFDT
EFFSEQ
BENEFIT_PROGRAM
A user wants to see the current benefit and current -1 benefit. To get the current benefit they are using a correlated subquery shown below in their where clause.
("PV_BEN_PROG_VW2"."EFFSEQ" = (
SELECT MAX("INNERALIAS"."EFFSEQ")
FROM "SYSADM"."PV_BEN_PROG_VW" INNERALIAS
WHERE "INNERALIAS"."EMPLID" = "PV_BEN_PROG_VW2"."EMPLID"
AND "INNERALIAS"."EFFDT" = "PV_BEN_PROG_VW2"."EFFDT")
AND
"PV_BEN_PROG_VW2"."EFFDT" = (
SELECT MAX("INNERALIAS"."EFFDT")
FROM "SYSADM"."PV_BEN_PROG_VW" INNERALIAS
WHERE "INNERALIAS"."EMPLID" = "PV_BEN_PROG_VW2"."EMPLID"))
To get the curent benefit -1 using a sub query in a sub query would get very messy. Is there a better way with newer SQL techniques?
Thanks
CharlesCook.com
ADP - PeopleSoft - SAP
ReportSmith - Crystal Reports - SQR - Query - Access
Reporting - Interfaces - Data Mining