select sum(case when updatetime>=DATEADD(mm, DATEDIFF(mm,0,getdate()), 0) and updatetime<=getdate() then MyMoney else 0 end) as ThisMonth, sum(case when updatetime>=dateadd(mm,-1,cast(cast(year(getdate()) as varchar)+'-'+cast(month(getdate()) as varchar)+'-01' as datetime)) and updatetime<=dateadd(mm,-1,cast(cast(year(getdate()) as varchar)+'-'+cast(month(getdate()) as varchar)+'-01' as datetime)) then MyMoney else 0 end) as LastMonth From JY_D_DivideOrderItem
--上月的第一天
select dateadd(mm,-1,cast(cast(year(getdate()) as varchar)+'-'+cast(month(getdate()) as varchar)+'-01' as datetime))
--本月的第一天
select cast(cast(month(getdate()) as varchar)+'-'+cast(month(getdate()) as varchar)+'-01' as datetime)
select dateadd(mm,datediff(mm,0,getdate()),0)
--上个月的最后一天 :本月第一天减2ms.
SELECT dateadd(ms,-2,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0))
--本月的最后一天
SELECT dateadd(ms,-2,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0))