Confused report

pts.
Tags:
SQL
Visual Basic
the code below is currently pulling a report in sql. I am trying to move that sql to visual basic to be a downloadable report. That is problem number one. Problem number 2; Currently my program goes in and grabs employee and dependents depending on the plan, so if they belong to a plan it will bring them in with their plan number as well as their plan strt cvg dt (coveragedate) for both. I need to have the program go in and look at the max coverage date for the family and use that for the coverage date for all as well as the ben. plan for all. For example; Dad employee test subject1 0007 1/1/04 Mom dependent test subject2 0011 12/31/05 Son dependent test subject3 0011 12/31/05 Son dependent test subject4 0011 12/31/05 I need to grab the max date (12/31/05) and apply it and Ben plan cd (0011) to Dad. SELECT DISTINCT 'V1.20MTCTECHF' VER,' ', LPAD(B.SSN_ID,13,'1800') EMPLOYEEID,' ', LPAD(B.SSN_ID,11,'0') EMPLOYEEIDD,' ', TO_CHAR(B.ORIG_HIRE_DT, 'YYYYMMDD') HIREDATE, ' ',B.LAST_NAME LASTNAME, B.FIRST_NAME FIRSTNAME, ' ', SUBSTR(B.MID_NAME,1,1) MIDNAME,' ', TO_CHAR(B.BIRTH_DT, 'YYYYMMDD') BIRTHDATE, B.SEX_CD SEXCD, B.MARITAL_CD MARITALCD, REPLACE(B.LN_1_ADR,'.','') ADR1, REPLACE(B.LN_2_ADR, '#','') ADR2, B.CITY_NAME CITY, B.MAIL_STATE_DC STATE, SUBSTR(B.POSTAL_CD,1,5) POSTAL, SUBSTR(B.COUNTRY_CD,1,2) COUNTRY, ' MM' MM, TO_CHAR(D.EFFECT_DT, 'YYYYMMDD') COVERAGESTART, '0700977 0700977' NUM,' ', DECODE(D.BEN_PLAN_CD,'UHCALL','0007','UHCBASIC','0011') STRUCTURE ,' ', DECODE(D.BEN_PLAN_CD,'UHCALL','0007','UHCBASIC','0011') STRUCTURE2 ,' ', 'PDG' MM2, TO_CHAR(D.EFFECT_DT, 'YYYYMMDD') COVERAGESTART2,' ', '0700977 0700977' NUM2,' ', DECODE(D.BEN_PLAN_CD,'UHCALL','0007','UHCBASIC','0011') STRUCTURE3,' ', DECODE(D.BEN_PLAN_CD,'UHCALL','0007','UHCBASIC','0011') STRUCTURE4, '|'||CHR(10) EM, 'V1.20MTCTECHF' DEPVER ,' ',DECODE(A.S_RELAT_DC,'Wife','01', 'Husband','01', 'Daughter','19', 'Son','19', 'Student', '20'), LPAD(B.SSN_ID,11,'0') DEPID, LPAD(REPLACE(A.DEP_SSN_ID,'-',''),11,'0'), ' ', TO_CHAR(B.ORIG_HIRE_DT, 'YYYYMMDD') DEPHIREDATE, ' ',A.LAST_NAME DEPLASTNAME, A.FIRST_NAME DEPFIRSTNAME,' ', SUBSTR(A.MID_NAME,1,1) DEPMIDNAME,' ', TO_CHAR(A.BIRTH_DT, 'YYYYMMDD') DEPBIRTHDATE, A.S_SEX_CD DEPSEXCD, 'U',' ', REPLACE(B.LN_1_ADR, '.','') DEPADR1, REPLACE(B.LN_2_ADR, '#','') DEPADR2, B.CITY_NAME DEPCITY, B.MAIL_STATE_DC DEPSTATE, SUBSTR(B.POSTAL_CD,1,5) DEPPOSTAL, SUBSTR(B.COUNTRY_CD,1,2) DEPCOUNTRY, ' MM', TO_CHAR(C.START_CVG_DT, 'YYYYMMDD') DEPCOVERAGESTART, '0700977 0700977',' ', DECODE(C.BEN_PLAN_CD, 'UHCALL','0007','UHCBASIC','0011') DEPSTRUCTURE,' ', DECODE(C.BEN_PLAN_CD,'UHCALL','0007','UHCBASIC','0011') DEPSTRUCTURE2,' ', 'PDG', TO_CHAR(C.START_CVG_DT, 'YYYYMMDD') DEPCOVERAGESTART2, ' ', '0700977 0700977', ' ', DECODE(C.BEN_PLAN_CD, 'UHCALL','0007','UHCBASIC','0011') DEPSTRUCTURE3,' ', DECODE(C.BEN_PLAN_CD, 'UHCALL','0007','UHCBASIC','0011') DEPSTRUCTURE4,' ', '|'||CHR(10) FROM EMPL B, HB_EMPL_PKG_ELEC D, HB_EMPL_DEP_BNFIC A, HB_EMPL_MED_DEP C WHERE B.EMPL_ID = A.EMPL_ID(+) AND C.EMPL_ID = A.EMPL_ID AND C.BEN_PLAN_CD IN ('UHCALL','UHCBASIC') AND B.EMPL_ID = D.EMPL_ID(+) AND D.BEN_PLAN_CD IN('UHCALL','UHCBASIC') AND B.S_EMPL_STATUS_CD='ACT' ORDER BY LASTNAME, VER, EMPLOYEEID, EMPLOYEEIDD, HIREDATE, FIRSTNAME, MIDNAME, BIRTHDATE, SEXCD, MARITALCD, ADR1, ADR2, CITY, STATE, POSTAL, COUNTRY, MM, COVERAGESTART, NUM, STRUCTURE, STRUCTURE2, MM2, COVERAGESTART2, NUM2, STRUCTURE3, STRUCTURE4;

Answer Wiki

Thanks. We'll let you know when a new response is added.

this is relatively easily achieved with an inline view, thus:

WITH plan_max_date as
(select ben_plan_cd, max(cvrg_Date) as mx_cvrg_dt
from whatever
group by plan_cd)
select …….. (original select statement here),
PMD.
FROM EMPL B,
HB_EMPL_PKG_ELEC D,
HB_EMPL_DEP_BNFIC A,
HB_EMPL_MED_DEP C,
plan_max_Date PMD
WHERE B.EMPL_ID = A.EMPL_ID(+) AND
C.EMPL_ID = A.EMPL_ID AND
C.BEN_PLAN_CD IN (‘UHCALL’,’UHCBASIC’)
and C.BEN_PLAN

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • FerencMantfeld
    this is relatively easily achieved with an inline view, thus: WITH plan_max_date as (select ben_plan_cd, max(cvrg_Date) as mx_cvrg_dt from whatever group by ben_plan_cd select ........ (original select statement here), PMD.mx_cvrg_dt /* here is the maximum coverage date from the inline view */ FROM EMPL B, HB_EMPL_PKG_ELEC D, HB_EMPL_DEP_BNFIC A, HB_EMPL_MED_DEP C, plan_max_Date PMD WHERE B.EMPL_ID = A.EMPL_ID(+) AND C.EMPL_ID = A.EMPL_ID AND C.BEN_PLAN_CD IN ('UHCALL','UHCBASIC') and C.BEN_PLAN_id = PMD.ben_pan_id .... rest of where clause .... That should do it just fine. Regards: Ferenc
    0 pointsBadges:
    report
  • FerencMantfeld
    this is relatively easily achieved with an inline view, thus: WITH plan_max_date as (select ben_plan_cd, max(cvrg_Date) as mx_cvrg_dt from whatever group by ben_plan_cd select ........ (original select statement here), PMD.mx_cvrg_dt /* here is the maximum coverage date from the inline view */ FROM EMPL B, HB_EMPL_PKG_ELEC D, HB_EMPL_DEP_BNFIC A, HB_EMPL_MED_DEP C, plan_max_Date PMD WHERE B.EMPL_ID = A.EMPL_ID(+) AND C.EMPL_ID = A.EMPL_ID AND C.BEN_PLAN_CD IN ('UHCALL','UHCBASIC') and C.BEN_PLAN_id = PMD.ben_pan_id .... rest of where clause .... That should do it just fine. Regards: Ferenc
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following