码迷,mamicode.com
首页 > 其他好文 > 详细

课表报表一个条件筛选时间段,可参考

时间:2015-01-28 12:52:40      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:

--正式课表查询
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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!