前30天convert(nvarchar(10),dateadd(day,-30,getdate()),120)
當月月初convert(varchar(10),dateadd(day,0,getdate()-day(getdate()-1)),120)
當月月末convert(varchar(10),dateadd(month,1,getdate()-day(getdate())),120)
其它非時間格式的表達計算
:rk_rq月初近兩月
rq>=convert(datetime,convert(varchar(4),year(:rk_rq))+'-'+convert(varchar(2),month(:rk_rq))+'-'+convert(varchar(2),day(:rk_rq)))-day(:rk_rq)+1
and rq<convert(datetime,convert(varchar(4),year(:rk_rq))+'-'+convert(varchar(2),month(:rk_rq)+2)+'-'+convert(varchar(2),day(:rk_rq)))-day(:rk_rq)+1
本文轉自 qvodnet 51CTO部落格,原文連結:http://blog.51cto.com/bks2015/1607438