本来是按月求和的 (select sum(Actual_D)from a where Month(Dtime) = month(@DTime) and year(Dtime) = year(@DTime) and delete_flag=0) as Actual_sum_m,
现在要求 从每个月的26号开始到下个月的25号为一个月的,这个该怎么写 求大虾们指教啊
现在要求 从每个月的26号开始到下个月的25号为一个月的,这个该怎么写 求大虾们指教啊
case when day(Dtime)>25 then month(Dtime)+1 else month(Dtime) end
先把两个日期计算出来,然后再比较啊
@d1 = '2013-5-25'
@d2 = '2013-6-26'
(select sum(Actual_D)from a where Dtime>=@d1 and Dtime<@d2 and delete_flag=0) as Actual_sum_m,
set @DTime='2013-5-25'select sum(Actual_D)
from a
where delete_flag=0 and
Dtime between
(case when day(@DTime)>=26 then CONVERT(varchar(8),@DTime,23)+'26'
else CONVERT(varchar(8),dateadd(mm,-1,@DTime),23)+'26' end)
and
(case when day(@DTime)>=26 then CONVERT(varchar(8),dateadd(mm,1,@DTime),23)+'25'
else CONVERT(varchar(8),@DTime,23)+'25' end)