Now that I have thousands of records it doesn't complete after 3 minutes (time out period).
Can you please help me look at the code and figure out areas that I could utilize views to make this more efficient?
Select EmpMe.Status as MyStatus, EmpMe.Full_Name as TheName, count(distinct Total_All.Client_ID) as Total_Clients, count(distinct Active_O.Client_ID) as Active_Ongoing, count(distinct InActive_O.Client_ID) as Inactive_Ongoing, count(distinct Total_O.Client_ID) as Total_Ongoing, count(distinct Active_R.Client_ID) as Active_Retros, count(distinct InActive_R.Client_ID) as Inactive_Retros, count(distinct Total_R.Client_ID) as Total_Retros, count(distinct Total_FW_Comps.Composite_ID) as Total_FW_Comp, count(distinct Total_PE_Comps.Composite_ID) as Total_PE_Comp, count(distinct Ongoing_FW_Comps.Composite_ID) as Ongoing_FW_Comp, count(distinct Ongoing_PE_Comps.Composite_ID) as Ongoing_PE_Comp, count(distinct Retro_FW_Comps.Composite_ID) as Retro_FW_Comp, count(distinct Retro_PE_Comps.Composite_ID) as Retro_PE_Comp FROM Engagements as E INNER JOIN Clients as C on C.ID = E.Client_ID INNER JOIN Rep_Client as RC on RC.Client_ID = C.ID and RC.Client_ID = E.Client_ID INNER JOIN Employees as EmpMe on EmpMe.ID = RC.Emp_ID LEFT JOIN ( select distinct Composite_ID, Comp.Client_ID from Composites Comp INNER JOIN Engagements as E on E.Client_ID = Comp.Client_ID WHERE E.Reports_Out is Null and E.Classification = 'Verification (Initial)' ) as Retro_FW_Comps on C.ID = Retro_FW_Comps.Client_ID LEFT JOIN ( select distinct Composite_ID, Comp.Client_ID from Composites Comp INNER JOIN Engagements as E on E.Client_ID = Comp.Client_ID WHERE E.Reports_Out is Null and E.Classification = 'Verification (Initial)' AND Comp.Perf_Exam = 'True' ) as Retro_PE_Comps on C.ID = Retro_PE_Comps.Client_ID LEFT JOIN ( select distinct Composite_ID, Comp.Client_ID from Composites Comp INNER JOIN Engagements as E on E.Client_ID = Comp.Client_ID WHERE E.Reports_Out is Null AND Comp.Perf_Exam = 'True' ) as Total_PE_Comps on C.ID = Total_PE_Comps.Client_ID LEFT JOIN ( select distinct Composite_ID, Comp.Client_ID from Composites Comp INNER JOIN Engagements as E on E.Client_ID = Comp.Client_ID WHERE E.Reports_Out is Null and E.Classification = 'Verification (Ongoing)' ) as Ongoing_FW_Comps on C.ID = Ongoing_FW_Comps.Client_ID LEFT JOIN ( select distinct Composite_ID, Comp.Client_ID from Composites Comp INNER JOIN Engagements as E on E.Client_ID = Comp.Client_ID WHERE E.Reports_Out is Null and E.Classification = 'Verification (Ongoing)' AND Comp.Perf_Exam = 'True' ) as Ongoing_PE_Comps on C.ID = Ongoing_PE_Comps.Client_ID LEFT JOIN ( select distinct Composite_ID, Comp.Client_ID from Composites Comp INNER JOIN Engagements as E on E.Client_ID = Comp.Client_ID WHERE E.Reports_Out is Null ) as Total_FW_Comps on C.ID = Total_FW_Comps.Client_ID Left JOIN ( select Distinct E.Client_ID from Engagements E WHERE E.Reports_Out is NULL and (E.Classification = 'Verification (Ongoing)' or E.Classification = 'Model Exam (Ongoing)' or E.Classification = 'Strategy Exam (Ongoing)' or E.Classification = 'AUP (Ongoing)') AND E.Inactive IS NULL ) As Active_O on C.ID = Active_O.Client_ID Left JOIN ( select Distinct E.Client_ID from Engagements E WHERE E.Reports_Out is NULL and (E.Classification = 'Verification (Ongoing)' or E.Classification = 'Model Exam (Ongoing)' or E.Classification = 'Strategy Exam (Ongoing)' or E.Classification = 'AUP (Ongoing)') AND E.Inactive IS NOT NULL ) As InActive_O on C.ID = InActive_O.Client_ID Left JOIN ( select Distinct E.Client_ID from Engagements E WHERE E.Reports_Out is NULL and (E.Classification = 'Verification (Initial)' or E.Classification = 'Model Exam (Initial)' or E.Classification = 'Strategy Exam (Initial)' or E.Classification = 'AUP (Initial)') AND E.Inactive IS NULL ) As Active_R on C.ID = Active_R.Client_ID Left JOIN ( select Distinct E.Client_ID from Engagements E WHERE E.Reports_Out is NULL and (E.Classification = 'Verification (Initial)' or E.Classification = 'Model Exam (Initial)' or E.Classification = 'Strategy Exam (Initial)' or E.Classification = 'AUP (Initial)') AND E.Inactive IS NOT NULL ) As InActive_R on C.ID = InActive_R.Client_ID Left JOIN ( select Distinct E.Client_ID from Engagements E WHERE E.Reports_Out is NULL and (E.Classification = 'Verification (Initial)' or E.Classification = 'Model Exam (Initial)' or E.Classification = 'Strategy Exam (Initial)' or E.Classification = 'AUP (Initial)') ) As Total_R on C.ID = Total_R.Client_ID Left JOIN ( select Distinct E.Client_ID from Engagements E WHERE E.Reports_Out is NULL and (E.Classification = 'Verification (Ongoing)' or E.Classification = 'Model Exam (Ongoing)' or E.Classification = 'Strategy Exam (Ongoing)' or E.Classification = 'AUP (Ongoing)') ) As Total_O on C.ID = Total_O.Client_ID Left JOIN ( select Distinct E.Client_ID from Engagements E WHERE E.Reports_Out is NULL ) As Total_All on C.ID = Total_All.Client_ID WHERE (EmpMe.Status = 'Partner' or EmpMe.Status = 'Sr. Manager' or EmpMe.Status = 'Manager' or EmpMe.Status = 'Lead Verifier') and RC.Eng_ID is Null Group By EmpMe.Status, EmpMe.Full_Name Order By MyStatus, TheName

New Topic/Question
Reply




MultiQuote





|