标签:
--正式课表查询
ALTER proc confirm_schedule_report(@bdate datetime,@edate datetime,@week varchar(10),@student varchar(100),@key varchar(50))
AS
SET NOCOUNT ON
BEGIN
IF(@week=‘上周‘ AND @bdate=‘‘ AND @edate=‘‘)
BEGIN
SET @bdate=(SELECT DATEADD(wk, DATEDIFF(wk,6,getdate()), 0))
SET @edate=(SELECT DATEADD(wk, DATEDIFF(wk,6,getdate()), 6))
END
IF(@week=‘本周‘ AND @bdate=‘‘ AND @edate=‘‘)
BEGIN
SET @bdate=(SELECT DATEADD(wk, DATEDIFF(wk,0,getdate()), 0))
SET @edate=(SELECT DATEADD(wk, DATEDIFF(wk,0,getdate()), 6))
END
IF(@week=‘下周‘ AND @bdate=‘‘ AND @edate=‘‘)
BEGIN
SET @bdate=(SELECT DATEADD(wk, DATEDIFF(wk,-6,getdate()), 0))
SET @edate=(SELECT DATEADD(wk, DATEDIFF(wk,-6,getdate()), 6))
END
SELECT CONVERT(VARCHAR(10),date,120) 日期,student 学生,MAX(aa) 第一节,MAX(bb) 第二节,MAX(cc) 第三节,MAX(dd) 第四节 FROM
(select distinct date,student,
case ClassHour when ‘1‘ then ‘[‘+course+‘,‘+coursetype+‘,‘+CASE [type] WHEN 0 THEN ‘主课‘ WHEN 1 THEN ‘辅课‘ ELSE ‘‘ END+‘,‘+teacher+‘],‘ end ‘aa‘,
case ClassHour when ‘2‘ then ‘[‘+course+‘,‘+coursetype+‘,‘+CASE [type] WHEN 0 THEN ‘主课‘ WHEN 1 THEN ‘辅课‘ ELSE ‘‘ END+‘,‘+teacher+‘],‘ end ‘bb‘,
case ClassHour when ‘3‘ then ‘[‘+course+‘,‘+coursetype+‘,‘+CASE [type] WHEN 0 THEN ‘主课‘ WHEN 1 THEN ‘辅课‘ ELSE ‘‘ END+‘,‘+teacher+‘],‘ end ‘cc‘,
case ClassHour when ‘4‘ then ‘[‘+course+‘,‘+coursetype+‘,‘+CASE [type] WHEN 0 THEN ‘主课‘ WHEN 1 THEN ‘辅课‘ ELSE ‘‘ END+‘,‘+teacher+‘],‘ end ‘dd‘
from Schedule) a
WHERE ((ISNULL(@bdate,‘‘)=‘‘ AND ISNULL(@edate,‘‘)=‘‘ )OR (date BETWEEN @bdate AND @edate))
AND (ISNULL(@student,‘‘)=‘‘ OR student LIKE ‘%‘+@student+‘%‘ )
AND (ISNULL(@key,‘‘)=‘‘ OR aa LIKE ‘%‘+@key+‘%‘ OR bb LIKE ‘%‘+@key+‘%‘ OR cc LIKE ‘%‘+@key+‘%‘ OR dd LIKE ‘%‘+@key+‘%‘ )
GROUP BY date,student
ORDER BY student asc,date asc
END
标签:
原文地址:http://www.cnblogs.com/chlf/p/4255388.html