日期:2014-05-18 浏览次数:20610 次
定义一个表 月份 开始日期 结束日期 1 12-26 01-25 2 01-26 02-25 3 02-26 03-25 4 03-26 04-25 5 04-26 05-25 6 05-26 06-25 .................... declare @riqi as datetime set @riqi = '2007-01-27' if (datepart(month,@riqi) = 11 and datepart(day,@riqi) > 25) or (datepart(month,@riqi) = 12 and datepart(day,@riqi) <= 25) print '12月份' else if (datepart(month,@riqi) = 12 and datepart(day,@riqi) > 25) or (datepart(month,@riqi) = 1 and datepart(day,@riqi) <= 25) print '1月份' else select 月份 from tb where @riqi >= datename(year,@riqi)+开始日期 and @riqi <= datename(year,@riqi)+结束日期
------解决方案--------------------
declare @date datetime set @date='2007-1-27' select Mon=case when datepart(day,@date)>=25 then datepart(month,@date)+1 else datepart(month,@date) end /* result Mon ----------- 2 (1 row(s) affected) */
------解决方案--------------------
declare @date datetime set @date='2007-12-27' select Mon=case when datepart(day,@date)>=25 then datepart(month,@date)%12+1 else datepart(month,@date) end /* result Mon ----------- 1 (1 row(s) affected) */