我正在使用以下查询运行报告,在Visual Studio中大约需要40秒,但在报告服务器中大约需要1分15秒
报告有4个数据集和3个参数。
QUERY:
SELECT PRPH_ML1,
Section,
AgeBand,
TermTimeWeekNo,
Sum(Mins_Poss) AS Mins_Poss,
Sum(Mins_Att) AS Mins_Att,
Sum(Mins_Late) AS Mins_Late,
REGT_Provision_Code,
PRPH_Title,
REGH_Class_Register,
REGH_Register_Title,
Section_Name,
Register_Day,
REGH_ISN,
PRPH_ISN,
REGH_Start_Time
FROM CurrentAttendance
WHERE ( CourseType IN ( @CourseType ) )
AND ( REGT_Year = @Year )
AND ( AgeBand IN ( @AgeBand ) )
GROUP BY PRPH_ML1,
Section,
AgeBand,
TermTimeWeekNo,
REGT_Provision_Code,
PRPH_Title,
REGH_Class_Register,
REGH_Register_Title,
Section_Name,
Register_Day,
REGH_ISN,
PRPH_ISN,
REGH_Start_Time
VIEW:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Sp_currentattendance_new]
AS
BEGIN
SET NOCOUNT ON;
---delete existing warehouse table------------------------------
IF Object_id('dbo.CurrentAttendance', 'U') IS NOT NULL
DROP TABLE dbo.CurrentAttendance;
--------Create New Table------------------------------------------------
---Weeks----------------------------------------------------------------
WITH weeks
AS (SELECT VDC_week_no,
VDC_cal_year,
Min(VDC_day_date) AS WeekCommence
FROM sql10.ng.dbo.Vdaily_calender
WHERE VDC_avail = 'T'
GROUP BY VDC_week_no,
VDC_cal_year),
---TTWeeks--------------------------------------------------------------
TTWeeks
AS (SELECT VDC_Cal_Year AS REMSYear,
[VDC_week_no] AS WholeYearWeekNo,
WeekCommence,
Row_number()
OVER(
PARTITION BY vdc_cal_year
ORDER BY VDC_week_no) AS TermTimeWeekNo
FROM weeks)
---Main---------------------------------------------------------------------
SELECT STYR_Primary_Programme AS PrimaryProgramme,
Rtrim(h2.PRPH_Title) AS PRPH_Title,
Rtrim(h2.PRPH_ML1) AS PRPH_ML1,
Rtrim(h2.PRPH_ML2) AS Section,
CASE
WHEN STYR_Age_end_Aug < 16 THEN '1416'
WHEN STYR_Age_end_Aug < 19 THEN '1618'
ELSE '19+'
END AgeBand,
rg.REGT_Year AS RegYear,
q.GNCD_Description AS [Curriculum Area],
q.GNCD_Description AS Section_Name,
LEFT(q.GNCD_Description, 3) AS Dept,
Rtrim(rg.REGT_Provision_Code) AS REGT_Provision_Code,
rg.REGT_Student_ID AS Student_ID,
STEN_Funding_Stream AS FundingStream,
rs.REGS_Session_No AS RegSession,
Rtrim(rh.REGH_Class_Register) AS Class_Register,
Rtrim(rh.REGH_Register_Title) AS Register_Title,
rh.REGH_Day AS ReghDay,
CASE
WHEN rh.REGH_Day = '1' THEN 'Sunday'
WHEN rh.REGH_Day = '2' THEN 'Monday'
WHEN rh.REGH_Day = '3' THEN 'Tuesday'
WHEN rh.REGH_Day = '4' THEN 'Wednesday'
WHEN rh.REGH_Day = '5' THEN 'Thursday'
WHEN rh.REGH_Day = '6' THEN 'Friday'
WHEN rh.REGH_Day = '7' THEN 'Saturday'
END AS Register_Day,
rh.[REGH_Start_Time] AS StartTime,
rh.[REGH_End_Time] AS EndTime,
CASE
WHEN ( rg.REGT_Provision_Code LIKE '27%'
OR rg.REGT_Provision_Code LIKE 'MA27%'
OR rg.REGT_Provision_Code LIKE 'FS%' ) THEN 'FunctionalSkill'
WHEN rg.REGT_Provision_Code LIKE '16%' THEN 'GCSE'
WHEN rg.REGT_Provision_Code LIKE '%/F%'
OR rg.REGT_Provision_Code LIKE '%/D%'
OR rg.REGT_Provision_Code LIKE '%/E%'
OR rg.REGT_Provision_Code LIKE '%/X%' THEN 'Main'
ELSE 'Addition'
END AS CourseType,
CASE
WHEN Isnull(ra.RGAT_Present, 'X') IN ( 'N', 'Y', 'X' )
AND rs.REGS_Session_Date < Getdate() THEN rs.REGS_Duration - Isnull(rd.REGD_Mins_Late, 0)
ELSE 0
END AS Mins_Poss,
CASE
WHEN Isnull(ra.RGAT_Present, 'X') = 'Y'
AND rs.REGS_Session_Date < Getdate() THEN rs.REGS_Duration - rd.REGD_Mins_Late
ELSE 0
END AS Mins_Att,
CASE
WHEN ra.RGAT_Present = 'Y'
AND rs.REGS_Session_Date < Getdate() THEN rd.REGD_Mins_Late
ELSE 0
END AS Mins_Late,
rs.[REGS_Session_Date] AS Session_Date,
TermTimeWeekNo AS TermTimeWeekNo,
rh.REGH_ISN AS REGHISN,
h2.PRPH_ISN AS PRPHISN,
st.STUD_Surname AS Surname,
st.STUD_Forename_1 AS Forename,
rd.REGD_Attendance_Mark AS AttendanceMark,
rg.REGT_start_date AS Startdate,
rg.REGT_End_date AS Enddate,
WeekCommence AS WeekStart
INTO CurrentAttendance
FROM sql10.ng.dbo.REGTrgstudt rg
INNER JOIN sql10.ng.dbo.REGSrgsessn rs
ON rg.REGT_REGH_ISN = rs.REGS_REGH_ISN
INNER JOIN sql10.ng.dbo.Vdaily_calender dc
ON rs.REGS_Session_Date = dc.VDC_day_date
INNER JOIN TTWeeks
ON rg.REGT_year = TTWeeks.REMSYear
AND dc.VDC_week_no = WholeYearWeekNo
AND dc.VDC_cal_year = REMSYear
INNER JOIN sql10.ng.dbo.REGHrghdr rh
ON rh.REGH_ISN = rg.REGT_REGH_ISN
INNER JOIN sql10.ng.dbo.PRPHProvisionHeader h
ON REGT_Provision_Code = h.PRPH_Code
INNER JOIN sql10.ng.dbo.STEN
ON STEN_Student_ID = rg.REGT_Student_ID
AND STEN_Provision_Code = rg.REGT_Provision_Code
AND STEN_Provision_Instance = rg.REGT_Provision_Instance
INNER JOIN sql10.ng.dbo.STYRstudentYR s
ON s.STYR_Student_ID = rg.REGT_Student_ID
AND s.STYR_Year = rg.REGT_Year
LEFT JOIN sql10.ng.dbo.PRPHProvisionHeader h2
ON h2.prph_code = s.STYR_Primary_Programme
INNER JOIN (SELECT ACYR_College_Year
FROM sql10.ng.dbo.ACYR
WHERE ( ACYR_ENR_PY_CY_NY IN ( 'CY' ) )) AS SUB
ON rg.REGT_Year = SUB.ACYR_College_Year
INNER JOIN sql10.ng.dbo.STUDStudent st
ON s.STYR_Student_ID = st.STUD_Student_ID
INNER JOIN sql10.ng.dbo.REGDropin rd
ON rg.REGT_REGH_ISN = rd.REGD_REGH_ISN
AND rg.REGT_Student_ID = rd.REGD_Student_ID
AND rd.REGD_Session_No = rs.REGS_Session_No
INNER JOIN sql10.ng.dbo.RGATAttendance ra
ON REGD_Attendance_Mark = ra.RGAT_Attendance_Code
INNER JOIN sql10.ng.dbo.PRPIProvisionInstance AS pit
ON pit.PRPI_Code = rg.REGT_Provision_Code
AND pit.prpi_instance = rg.REGT_Provision_Instance
INNER JOIN (SELECT GNCD_General_Code,
GNCD_Description
FROM sql10.ng.dbo.GNCDgncodes
WHERE ( GNCD_Code_Type = 'M2' )) AS q
ON q.GNCD_General_Code = Rtrim(h2.PRPH_ML2)
END
你能否提出一些改善表现的建议。