case when SUBSTRING(CONVERT(varchar(10), business_date_key, 112),0,7)=
SUBSTRING(convert(varchar(10),getdate(),112),0,7) then '本月' else '' end AS month1,
case when SUBSTRING(CONVERT(varchar(10), business_date_key, 112),0,7)=
SUBSTRING(convert(varchar(10),getdate(),112),0,7)-1 then '上月' else '' end as month2根据business_date_key 来算上季度
格式和本月上月一样。。求sql高人。
case datediff(quarter, business_date_ke, getdate()) when 1 then '上季度' when 0 then '本季度' else '' end
case datediff(quarter, ltrim(business_date_ke), getdate()) when 1 then '上季度' when 0 then '本季度' else '' end
DATEDIFF
返回跨两个指定日期的日期和时间边界数。 语法
DATEDIFF ( datepart , startdate , enddate ) 参数
datepart是规定了应在日期的哪一部分计算差额的参数。下表列出了 Microsoft® SQL Server™ 识别的日期部分和缩写。日期部分 缩写
year yy, yyyy
quarter qq, q
Month mm, m
dayofyear dy, y
Day dd, d
Week wk, ww
Hour hh
minute mi, n
second ss, s
millisecond ms