我正在尝试将缺席日期分配到学年,学年是8月1日到7月31日.
所以我想要的是:
31/07/2007 = 2006/2007
02/10/2007 = 2007/2008
08/01/2008 = 2007/2008
有没有一种简单的方法在sql 2000服务器中执行此操作.
具有较少字符串处理的变体
SELECT AbsenceDate, CASE WHEN MONTH(AbsenceDate) <= 7 THEN CONVERT(VARCHAR(4), YEAR(AbsenceDate) - 1) + '/' + CONVERT(VARCHAR(4), YEAR(AbsenceDate)) ELSE CONVERT(VARCHAR(4), YEAR(AbsenceDate)) + '/' + CONVERT(VARCHAR(4), YEAR(AbsenceDate) + 1) END AcademicYear FROM AbsenceTable
结果:
2007-07-31 => '2006/2007' 2007-10-02 => '2007/2008' 2008-01-08 => '2007/2008'