Report second try

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'

Answer Wiki

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

Thank you for visiting ITKE.

We are happy to help you with solving specific IT questions, but need as
much information as possible to do so. Let us know about the problem you
are trying to solve, how you are approaching it and what work you’ve
done so far, and we can help guide you in the right direction.

Discuss This Question: 5  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
  • Alex8809
    i've seen thousands and thousands of questions on database discussion forums, and dozens of homework questions, and there's NO WAY that's a homework question
    0 pointsBadges:
    report
  • Alex8809
    This is not a homework assignment, my last day at school was about 5 years ago.
    0 pointsBadges:
    report
  • Cglancy
    Please accept my humble apology and wish for finding an easy solution to your dilema.
    0 pointsBadges:
    report
  • DonnaTX
    Write a server side program to file and query for the result. If you are runnning this from an SQL procedure, then this should be no problem. Perhaps you should consider using a two step SQL. Good Luck
    0 pointsBadges:
    report
  • FerencMantfeld
    I have had a similar kind of problem before and resolved it relatively simply with a single-pass SQL solution, placing the aggregation (max cvrg_date) into an inline view and then joining this inline view which will give you a virtual table, to the main query. Try this: 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. alternatively, try this: select ........ (original select statement here), PMD.mx_cvrg_dt /* here is the maximum coverage date from the inline view */ FROM EMPL B, ( select ben_plan_cd, max(cvrg_Date) as mx_cvrg_dt from whatever group by ben_plan_cd) PMD, 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 C.BEN_PLAN_id = PMD.ben_plan_cd /* this is where we join the inline view to the rest of the query, simplyfying things */ .... rest of where clause .... 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