问题描述
以下是出生日期范围,用于计算学年: 我要检查孩子上哪个学年的约会,如果约会是去年,那么显示孩子去年的学年?
RECEPTION 1/9/15—31/8/16
YEAR 1 1/9/14—31/8/15
YEAR 2 1/9/13—31/8/14
YEAR 3 1/9/12–31/8/13
YEAR 4 1/9/11—31/8/12
YEAR 5 1/9/10—31/8/11
YEAR 6 1/9/09—31/8/10
YEAR 7 1/9/08—31/8/09
YEAR 8 1/9/07—31/8/08
YEAR 9 1/9/06–31/8/07
YEAR 10 1/9/05—31/8/06
YEAR 11 1/9/04—31/8/05
YEAR 12 1/9/03—31/8/04
YEAR 13 1/9/02—31/8/03
到目前为止,我已经尝试过了,我可以获得孩子目前所在的年份,但是无法计算孩子约会时所在的学年。
,CASE
WHEN (datepart(year,getdate()) - (CASE WHEN (DATEPART(MONTH,dd.[Date of Birth]) >8) THEN (datepart(Year,dd.[Date of Birth])+5)
ELSE (datepart(Year,dd.[Date of Birth])+4) END))='0' THEN 'Reception'
WHEN (datepart(year,dd.[Date of Birth])+4) END))='1' THEN 'Year 1'
WHEN (datepart(year,dd.[Date of Birth])+4) END))='2' THEN 'Year 2'
WHEN (datepart(year,dd.[Date of Birth])+4) END))='3' THEN 'Year 3'
WHEN (datepart(year,dd.[Date of Birth])+4) END))='4' THEN 'Year 4'
WHEN (datepart(year,dd.[Date of Birth])+4) END))='5' THEN 'Year 5'
WHEN (datepart(year,dd.[Date of Birth])+4) END))='6' THEN 'Year 6'
WHEN (datepart(year,dd.[Date of Birth])+4) END))='7' THEN 'Year 7'
WHEN (datepart(year,dd.[Date of Birth])+4) END))='8' THEN 'Year 8'
WHEN (datepart(year,dd.[Date of Birth])+4) END))='9' THEN 'Year 9'
WHEN (datepart(year,dd.[Date of Birth])+4) END))='10' THEN 'Year 10'
WHEN (datepart(year,dd.[Date of Birth])+4) END))='11' THEN 'Year 11'
WHEN (datepart(year,dd.[Date of Birth])+4) END))='12' THEN 'Year 12'
WHEN (datepart(year,dd.[Date of Birth])+4) END))='13' THEN 'Year 13'
WHEN (datepart(year,dd.[Date of Birth])+4) END))>'13' THEN 'Above Year 13'
ELSE 'Not in School' end
预先感谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)