我有一个包含3个参数的报告,旨在显示主要课程的出勤率。
它应显示所有列的数据,但对于GCSE列(见下图)报告不显示除3行之外的任何数据(显示大量空白).Dataset-CourseType
查询:
SELECT DISTINCT
PrimaryProgramme, PRPH_Title, PRPH_ML1,
Section, AgeBand, REGT_Year, Section_Name,
REGT_Provision_Code, STEN_Student_ID,
CourseType, Mins_Poss, Mins_Att,
Mins_Late, TermTimeWeekNo, STUD_Surname,
Class_Register COLLATE DATABASE_DEFAULT + ' - ' +
Register_Title COLLATE DATABASE_DEFAULT + ' - ' +
Register_Day COLLATE DATABASE_DEFAULT + ' ' + CONVERT(char(5),
StartTime, 108) + ' - ' + CONVERT(char(5), EndTime, 108) AS Register
FROM CurrentAttendance_New
WHERE (REGT_Year = @Year)
AND (AgeBand IN (@AgeBand))
AND (CourseType IN (@CourseType))
ORDER BY PrimaryProgramme
AgeBand:
SELECT DISTINCT AgeBand
FROM CurrentAttendance_New
WHERE (REGT_Year = @Year)
CourseType:
SELECT DISTINCT CourseType
FROM CurrentAttendance_New
WHERE (AgeBand IN (@AgeBand))
CurrentAttendance_New(Stored Procedure which is used in datasets):
IF OBJECT_ID('dbo.CurrentAttendance_New', 'U') IS NOT NULL
DROP TABLE dbo.CurrentAttendance_New;
--------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 DISTINCT
s.STYR_Primary_Programme AS PrimaryProgramme,
CASE WHEN s.STYR_Age_end_Aug < 16 THEN '1416'
WHEN STYR_Age_end_Aug < 19 THEN '1618' ELSE '19+' END AgeBand,
rg.REGT_Year,
RTRIM(ph.PRPH_ML1) AS PRPH_ML1,
q.GNCD_Description AS [Curriculum Area],
RTRIM(ph.PRPH_ML2) AS Section,
q.GNCD_Description AS Section_Name,
LEFT(q.GNCD_Description, 3) AS Dept,
RTRIM(rg.REGT_Provision_Code) as REGT_Provision_Code,
RTRIM(ph.PRPH_Title) as PRPH_Title,
rm.ROOM_Room_No as RoomNo,
rg.REGT_Student_ID, STEN_Student_ID, STEN_Funding_Stream,
rs.REGS_Session_No,
RTRIM(rh.REGH_Class_Register) as Class_Register,
RTRIM(rh.REGH_Register_Title) as Register_Title,
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,
rl.RGHL_Lecturer_Code AS LectCode,
RTRIM(PS.PERS_Forename) + ' ' + RTRIM(PS.PERS_Surname) AS LectName,
RTRIM(PS.PERS_Department_ML) AS LectDepartment,
RTRIM(PS.PERS_Grade) AS LectSection,
rs.[REGS_Session_Date] as Session_Date,
TermTimeWeekNo,
rh.REGH_ISN, ph.PRPH_ISN, st.STUD_Surname, st.STUD_Forename_1, rd.REGD_Attendance_Mark,
rg.REGT_start_date, rg.REGT_End_date, WeekCommence
,FME.STFM_LearnFAMCode as FreeMealsCode,
LSR.STFM_LearnFAMCode as LearnerSupportCode,
CASE
WHEN FME.STFM_LearnFAMCode=1 THEN '14-15 year old learner is eligible for free meals'
WHEN FME.STFM_LearnFAMCode=2 THEN '16-19 year old learner is eligible for and in receipt of free meals'
ELSE 'N/A'
END AS FreeMealsIndicator,
CASE
WHEN LSR.STFM_LearnFAMCode=36 THEN 'Care to Learn (C2L) (EFA funded only)'
WHEN LSR.STFM_LearnFAMCode=55 THEN '16-19 Bursary Fund - learner member of a vulnerable group (EFA funded only)'
WHEN LSR.STFM_LearnFAMCode=56 THEN '16-19 Bursary Fund - learner awarded discretionary bursary (EFA funded only)'
WHEN LSR.STFM_LearnFAMCode=57 THEN 'Residential support (EFA funded only)'
WHEN LSR.STFM_LearnFAMCode=58 THEN '19+ Hardship (Skills Funding Agency funded learners only)'
WHEN LSR.STFM_LearnFAMCode=59 THEN '20+ Childcare (Skills Funding Agency funded learners only)'
WHEN LSR.STFM_LearnFAMCode=60 THEN 'Residential Access Fund (Skills Funding Agency funded learners only)'
WHEN LSR.STFM_LearnFAMCode IN (61, 62, 63, 64, 65) THEN 'Unassigned'
ELSE 'N/A'
END AS Bursary,
CASE
WHEN st.STUD_Gender='M' THEN 'Male'
WHEN st.STUD_Gender='F' THEN 'Female'
END AS Gender,
CASE
WHEN st.STUD_Ethnicity= 31 THEN 'White - English / Welsh / Scottish / Northern Irish / British'
WHEN st.STUD_Ethnicity= 32 THEN 'White - Irish'
WHEN st.STUD_Ethnicity= 33 THEN 'White - Gypsy or Irish Traveller'
WHEN st.STUD_Ethnicity= 34 THEN 'White - Any Other White background'
WHEN st.STUD_Ethnicity= 35 THEN 'Mixed / Multiple Ethnic group - White and Black Caribbean'
WHEN st.STUD_Ethnicity= 36 THEN 'Mixed / Multiple Ethnic group - White and Black African'
WHEN st.STUD_Ethnicity= 37 THEN 'Mixed / Multiple Ethnic group - White and Asian'
WHEN st.STUD_Ethnicity= 38 THEN 'Mixed / Multiple Ethnic group - Any Other Mixed / multiple ethnic background'
WHEN st.STUD_Ethnicity= 39 THEN 'Asian / Asian British - Indian'
WHEN st.STUD_Ethnicity= 40 THEN 'Asian/ Asian British - Pakistani'
WHEN st.STUD_Ethnicity= 41 THEN 'Asian / Asian British - Bangladeshi'
WHEN st.STUD_Ethnicity= 42 THEN 'Asian / Asian British - Chinese'
WHEN st.STUD_Ethnicity= 43 THEN 'Asian / Asian British - Any other Asian background'
WHEN st.STUD_Ethnicity= 44 THEN 'Black / African / Caribbean / Black British - African'
WHEN st.STUD_Ethnicity= 45 THEN 'Black / African / Caribbean / Black British - Caribbean'
WHEN st.STUD_Ethnicity= 46 THEN 'Black / African / Caribbean / Black British - Any other Black / African / Caribbean background'
WHEN st.STUD_Ethnicity= 47 THEN 'Other ethnic group - Arab'
WHEN st.STUD_Ethnicity= 98 THEN 'Any Other'
WHEN st.STUD_Ethnicity= 99 THEN 'Not provided'
END AS Ethnicity,
CASE
WHEN g.GNUC_Flag_1 = 1 THEN 'Yes'
else 'No'
END AS [Looked After Child],
CASE
WHEN sub1.GNUC_Code_4 = 'Y' THEN 'Yes'
ELSE 'No'
END AS ALS
INTO dbo.CurrentAttendance_New
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
ON rs.REGS_Session_Date=VDC_day_date
INNER JOIN TTWeeks on rg.REGT_year=TTWeeks.REMSYear
and VDC_week_no=WholeYearWeekNo AND VDC_cal_year=REMSYear
INNER JOIN
sql10.ng.dbo.REGHrghdr rh ON rh.REGH_ISN = rg.REGT_REGH_ISN
INNER JOIN
sql10.ng.dbo.RGSRSessRoom rgs ON rh.REGH_ISN = rgs.RGSR_REGH_ISN
INNER JOIN
sql10.ng.dbo.ROOMrooms rm ON rgs.RGSR_Room = rm.ROOM_Room_No
left outer JOIN sql10.ng.dbo.RGHLHeadLect AS RL
ON REGH_ISN = RL.RGHL_REGH_ISN AND RL.RGHL_Main = 1
INNER JOIN
sql10.ng.dbo.PRPHProvisionHeader ph ON rg.REGT_Provision_Code = ph.PRPH_Code
LEFT outer JOIN sql10.ng.dbo.PERSstaff AS PS
ON RL.RGHL_Lecturer_Code = PS.PERS_Staff_Code
AND RL.RGHL_Main = 1 AND rh.REGH_ISN = RL.RGHL_REGH_ISN
AND PS.PERS_Grade = ph.PRPH_ML2
INNER JOIN
sql10.ng.dbo.GNCDgncodes AS ML2 ON ML2.GNCD_General_Code = ph.PRPH_ML2
AND ML2.GNCD_Code_Type = 'M2'
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
LEFT OUTER JOIN sql10.ng.dbo.STFMLearnerFAM as LSR
ON LSR.STFM_Year = STEN_Year
AND LSR.STFM_Student_ID = STEN_Student_ID and LSR.STFM_LearnFAMType='LSR'
LEFT OUTER JOIN sql10.ng.dbo.STFMLearnerFAM as FME
ON FME.STFM_Year = STEN_Year
AND FME.STFM_Student_ID = STEN_Student_ID and FME.STFM_LearnFAMType='FME'
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.GNUCustom sub1
ON rg.REGT_Year = SUB1.GNUC_Year
AND STYR_ISN = SUB1.GNUC_Entity_ISN
AND GNUC_Type = 'STYR'
INNER JOIN
(SELECT ACYR_College_Year
FROM sql10.ng.dbo.ACYR
WHERE (ACYR_ENR_PY_CY_NY = ('CY'))) AS SUB
ON REGT_Year = SUB.ACYR_College_Year
INNER JOIN sql10.ng.dbo.STUDStudent st on s.STYR_Student_ID=st.STUD_Student_ID
LEFT JOIN sql10.ng.dbo.GNUCustom g ON STUD_ISN = g.GNUC_Entity_ISN
AND g.GNUC_Type = 'STUD'
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 rd.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 = 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(ph.PRPH_ML2)
END
GO