Here is my Query
the
-- Standard_Presets ------------------------------------------------------------------------------------ START
Standard_Presets As (
Select
1 HANDLE
, :Date_Range_Option Date_Range -- SQL Dev
, Epic_Util.Efn_Din(:Start_Date) START_Date -- SQL Dev
, Epic_Util.Efn_Din(:End_Date) + .99999 End_Date -- SQL Dev
From Dual
)
-- Date_Selection ------------------------------------------------------------------------------------ START
, Date_Selection as (
Select 1 HANDLE
,(Case PRE.date_range
When 'Yesterday' Then Trunc(Sysdate ) - 1
When 'Last 7 Days' Then Trunc(Sysdate ) - 7
When 'Last Full Week' Then Trunc(Sysdate, 'D' ) - 7
When 'Last Full Week - 1' Then Trunc(Sysdate, 'D' ) - 14 -- STARTing on Sunday
When 'Last Full MidWeek' Then Trunc(Sysdate, 'D' ) - 4 -- STARTing on Wednesday
When 'Last Full MidWeek - 1' Then Trunc(Sysdate, 'D' ) - 11 -- STARTing on Wednesday
When 'Month To Date' Then Trunc(Sysdate, 'MM')
When 'Last Full Month' Then add_months(Trunc(Sysdate, 'MM'),-1)
When 'Last Full Month - 1' Then add_months(Trunc(Sysdate, 'MM'),-2)
When 'Previous 30 Days' Then Trunc(Sysdate ) - 30
When 'Year to Date (Days)' Then Trunc(Sysdate, 'Y' )
When 'Year To Date (Months)' Then Trunc(Sysdate, 'Y' )
Else PRE.START_date -- Custom Date Range
End) Dt_From
,(Case PRE.date_range
When 'Yesterday' Then Trunc(Sysdate) - .00001
When 'Last 7 Days' Then Trunc(Sysdate) - .00001
When 'Last Full Week' Then Trunc(Sysdate, 'D' ) - .00001
When 'Last Full Week - 1' Then Trunc(Sysdate, 'D' ) - 7.00001
When 'Last Full MidWeek' Then Trunc(Sysdate, 'D' ) + 2.99999 -- ending on Tuesday
When 'Last Full MidWeek - 1' Then Trunc(Sysdate, 'D' ) - 4.00001 -- ending on Tuesday
When 'Month To Date' Then Trunc(Sysdate) - .00001
When 'Last Full Month' Then trunc(sysdate, 'MM') - .00001
When 'Last Full Month - 1' Then add_months(Trunc(Sysdate, 'MM'),-1) - .00001
When 'Previous 30 Days' Then Trunc(Sysdate) - .00001
When 'Year To Date (Days)' Then Trunc(Sysdate) - .00001
When 'Year To Date (Months)' Then trunc(sysdate, 'MM') - .00001
Else PRE.end_date -- Custom Date Range
End) Dt_Thru
From Standard_Presets PRE
)
-- Date_Selection ------------------------------------------------------------------------------------ end
-- Standard_Base_Population ------------------------------------------------------------------------------------ start
, Standard_Base_Population as (
Select
ENC.pat_id Pat_Id
, ENC.pat_enc_csn_id Pat_Enc_Csn_Id
, IID.identity_id Identity_Id
, ENC.contact_date Contact_Date
, ENC.appt_status_c Appt_Status_C
, ENC.enc_type_c Enc_Type_C
, ENC.hsp_account_id Hsp_Account_Id
, ENC.account_id Guarantor_Id
, ENC.visit_prov_id Visit_Prov_Id
------ Report Parameters ------ Crystal Needs
, DEP.rpt_grp_trtyseven_c rpt_grp_trtyseven_c -- Ownership -- Formula(s): DIR1,DIR2,DIR3,DIR4,DIR5
, CSA.serv_area_id serv_area_id -- ServiceArea
, DEP.rpt_grp_trtyfour_c rpt_grp_trtyfour_c -- Market
, LOC.loc_id loc_id -- Location
, ENC.effective_dept_id Department_ID -- Department -- Formula(s): DIR1,DIR2,DIR3,DIR4,DIR5 -- use txn dept for display
, Nvl(Csa.Serv_Area_Name, 'Undefined Service Area') Serv_Area_Name -- Group Header #1
, Nvl(Loc.Loc_Name, 'Undefined Location') Loc_Name -- Group Header #2, Page Header b
, Nvl(Dep.Department_Name,'Undefined Department') Department_Name -- Group Header #3 -- use txn dept for display
, DEP.rpt_grp_thirtysix_c rpt_grp_thirtysix_c -- Formula(s): DIR1,DIR2,DIR3,DIR4,DIR5
, DEP.rev_loc_id rev_loc_id -- Formula(s): DIR2
From pat_enc ENC
join date_selection DTS on DTS.handle = 1
Join clarity_dep DEP on DEP.department_id = ENC.effective_dept_id
Join clarity_loc LOC on LOC.loc_id = DEP.rev_loc_id
Left Join clarity_sa CSA on CSA.serv_area_id = LOC.serv_area_id
Join identity_id IID on IID.identity_type_id = LOC.id_type
and IID.pat_id = ENC.pat_id
JOIN HSP_TRANSACTIONS HSP ON HSP.HSP_ACCOUNT_ID = ENC.HSP_ACCOUNT_ID
Where 1=1
and ( ENC.appt_status_c is null -- for hospital visits and home care visits
or ENC.appt_status_c in ( 2 -- completed
, 6 -- arrived
) )
AND ENC.CONTACT_DATE >= DTS.Dt_From
and ENC.CONTACT_DATE <= DTS.Dt_Thru
And ( ('0' = :Ownership ) or (Dep.Rpt_Grp_Trtyseven_C in (:Ownership ) ) ) -- SQL Dev 1
And ( ( 0 = :ServiceArea ) or (Csa.Serv_Area_Id in (:ServiceArea ) ) ) -- SQL Dev 10
And ( ('0' = :Market ) or (Dep.Rpt_Grp_Trtyfour_C in (:Market ) ) ) -- SQL Dev 500
And ( ( 0 = :Location ) or (Loc.Loc_Id in (:Location ) ) ) -- SQL Dev 1100
And ( ( 0 = :Department ) or (Dep.Department_Id in (:Department ) ) ) -- SQL Dev 0
And ( ('0' = :EncounterType ) or (ENC.enc_type_c in (:EncounterType) ) ) -- SQL Dev 3 = hospital
)
select
SBP.Pat_Enc_Csn_Id
, SBP.*
from Standard_Base_Population SBP
What I have tried:
As long as I have the statement , SBP.* the query works fine but if I comment out the ,SBP.* the query appears to run forever. Any ideas.
I am using SQL Developer evr 17.4 and the Oracle DB version is 12.C Rel 12.1.0.2.0