DepartmentWithSchedule.sql 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. select demc.*,s.Code as SchoolyearCode,d.Name as DepartmentName,c.No AS CollegeNo,
  2. w.Weekday,w.WeekdayDesc,case when right(es.WeekNums,1)=',' then substring(es.WeekNums,0,LEN(es.WeekNums)) else es.WeekNums end as WeekNums,es.ClassroomID,
  3. es.Name as ClassroomName,es.StartTimes,es.Times,es.StopWeekNumStr
  4. from (
  5. select distinct x.*
  6. from (
  7. select cm.CourseName,emc.EducationMissionClassID,emc.Name as EducationMissionClassName,
  8. ISNULL(emcts.TheoryCourse,0)+
  9. ISNULL(emcts.Practicehours,0) as TotalHours,
  10. esccs.StudentCount,u.Name as TeacherName,dit.Name as TitleDesc,em.SchoolyearID,
  11. em.DepartmentID,emc.HandleModeID,
  12. g.GradeID as GradeYearID,f.StandardID,emc.OrderNo
  13. from ES_EducationScheduling es
  14. inner join EM_CoursesTime ct on es.CoursesTimeID=ct.CoursesTimeID
  15. inner join ES_EducationSchedulingTeacher est on es.EducationSchedulingID=est.EducationSchedulingID
  16. inner join CF_Staff s on est.UserID=s.UserID
  17. inner join Sys_User u on s.UserID=u.UserID
  18. inner join EM_EducationSchedulingClass esc on es.EducationSchedulingClassID=esc.EducationSchedulingClassID
  19. inner join EM_EducationMissionClass emc on esc.EducationMissionClassID=emc.EducationMissionClassID
  20. inner join EM_EducationMission em on emc.EducationMissionID=em.EducationMissionID
  21. inner join EM_EducationMissionClassTeachingSetting emcts on emc.EducationMissionClassID=emcts.EducationMissionClassID
  22. left join EM_Coursematerial cm on emc.CoursematerialID=cm.CoursematerialID
  23. left join CF_Classmajor c on emc.MainScheduleClassID=c.ClassmajorID
  24. left join CF_Grademajor g on c.GrademajorID = g.GrademajorID
  25. left join CF_Facultymajor f on g.FacultymajorID = f.FacultymajorID
  26. left join Sys_DictionaryItem dit on dit.DictionaryCode='CF_Title' and dit.Value=s.TitleID
  27. left join (
  28. select EducationSchedulingClassID,COUNT(1) as StudentCount
  29. from EM_EducationSchedulingClass_CF_Student
  30. group by EducationSchedulingClassID
  31. ) esccs on esc.EducationSchedulingClassID=esccs.EducationSchedulingClassID
  32. where ct.RecordStatus>0
  33. ) x
  34. ) demc
  35. inner join CF_Schoolyear s on demc.SchoolyearID=s.SchoolyearID
  36. inner join CF_Department d on demc.DepartmentID=d.DepartmentID
  37. inner join CF_College c on d.CollegeID=c.CollegeID
  38. full join (
  39. select 1 as Weekday,'星期一' as WeekdayDesc
  40. union all
  41. select 2 as Weekday,'星期二' as WeekdayDesc
  42. union all
  43. select 3 as Weekday,'星期三' as WeekdayDesc
  44. union all
  45. select 4 as Weekday,'星期四' as WeekdayDesc
  46. union all
  47. select 5 as Weekday,'星期五' as WeekdayDesc
  48. union all
  49. select 6 as Weekday,'星期六' as WeekdayDesc
  50. union all
  51. select 0 as Weekday,'星期日' as WeekdayDesc
  52. ) w on 1=1
  53. left join (
  54. select x.EducationMissionClassID,x.Weekday,x.ClassroomID,x.Name,x.StartTimes,x.Times,STUFF((select convert(varchar(10),esw.WeekNum)+','
  55. from ES_EducationScheduling es
  56. inner join ES_EducationSchedulingWeekNum esw on es.EducationSchedulingID=esw.EducationSchedulingID
  57. inner join EM_EducationSchedulingClass esc on es.EducationSchedulingClassID=esc.EducationSchedulingClassID
  58. group by esc.EducationMissionClassID,es.Weekday,es.ClassroomID,esw.WeekNum
  59. having esc.EducationMissionClassID=x.EducationMissionClassID and es.Weekday=x.Weekday
  60. and es.ClassroomID=x.ClassroomID
  61. and STUFF((select ','+CONVERT(varchar(10),ctt.StartTimes)+','+CONVERT(varchar(10),ctt.EndTimes)
  62. from ES_EducationScheduling est
  63. inner join EM_CoursesTime ctt on est.CoursesTimeID=ctt.CoursesTimeID
  64. inner join EM_EducationSchedulingClass esct on est.EducationSchedulingClassID=esct.EducationSchedulingClassID
  65. where esct.EducationMissionClassID=esc.EducationMissionClassID
  66. and est.ClassroomID=es.ClassroomID
  67. and est.Weekday=es.Weekday and ctt.RecordStatus>0
  68. order by ctt.StartTimes
  69. for xml path('')), 1, 1, '')=x.Times
  70. order by esw.WeekNum
  71. for xml path('')
  72. ), 1, 0, '') as WeekNums,
  73. x.StopWeekNumStr
  74. from (
  75. select esc.EducationMissionClassID,es.Weekday,c.ClassroomID,c.Name,Min(ct.StartTimes) as StartTimes,STUFF((select ','+CONVERT(varchar(10),ctt.StartTimes)+','+CONVERT(varchar(10),ctt.EndTimes)
  76. from ES_EducationScheduling est
  77. inner join EM_CoursesTime ctt on est.CoursesTimeID=ctt.CoursesTimeID
  78. inner join EM_EducationSchedulingClass esct on est.EducationSchedulingClassID=esct.EducationSchedulingClassID
  79. inner join CF_Classroom ct on est.ClassroomID=ct.ClassroomID
  80. where esct.EducationMissionClassID=esc.EducationMissionClassID
  81. and ct.ClassroomID=c.ClassroomID
  82. and est.Weekday=es.Weekday and ctt.RecordStatus>0
  83. order by ctt.StartTimes
  84. for xml path('')), 1, 1, '') as Times,STUFF((select ','+Convert(varchar(10),ISNULL(tess.WeekNum,0))
  85. from ES_EducationSchedulingStop tess
  86. inner join ES_EducationSchedulingStopTeacher tesst on tess.EducationSchedulingStopID=tesst.EducationSchedulingStopID
  87. inner join Sys_DictionaryItem ttm on ttm.DictionaryCode='EM_TeachingMethod' and ttm.Code='Lecturer' and tesst.TeachingMethod=ttm.Value
  88. inner join EM_EducationMissionClass temc on tess.EducationMissionClassID=temc.EducationMissionClassID
  89. where tess.EducationMissionClassID=esc.EducationMissionClassID
  90. and tess.ClassroomID=c.ClassroomID
  91. and tess.Weekday=es.Weekday and tess.RecordStatus=3
  92. order by ISNULL(tess.WeekNum,0)
  93. for xml path('')), 1, 1, '') as StopWeekNumStr
  94. from ES_EducationScheduling es
  95. inner join EM_CoursesTime ct on es.CoursesTimeID=ct.CoursesTimeID
  96. inner join EM_EducationSchedulingClass esc on es.EducationSchedulingClassID=esc.EducationSchedulingClassID
  97. inner join CF_Classroom c on es.ClassroomID=c.ClassroomID
  98. where ct.RecordStatus>0
  99. group by esc.EducationMissionClassID,es.Weekday,c.ClassroomID,c.Name
  100. ) x
  101. group by x.EducationMissionClassID,x.Weekday,x.ClassroomID,x.Name,x.StartTimes,x.Times,x.StopWeekNumStr
  102. ) es on demc.EducationMissionClassID=es.EducationMissionClassID and w.Weekday=es.Weekday
  103. where demc.SchoolyearID=@SchoolyearID
  104. and d.CollegeID=@CollegeID
  105. and d.DepartmentID=@DepartmentID
  106. and (demc.HandleModeID=@HandleModeID or @HandleModeID is null)
  107. order by demc.CourseName,demc.EducationMissionClassName,demc.TeacherName;