sqlserver 取日期年份月份

select convert(varchar(10),datepart(YYYY,a.fssj)) as years,--得到年份
convert(varchar(10),datepart(mm,a.fssj)) as months,--得到月份
sum(case when b.fszt in ('1','2') then a.cfs else 0 end) as fscgnumber,
sum(a.cfs) as fsnumber
from T_MTN_Sendrecord a
inner join T_MTN_SendNote b on a.dxdm=b.dxdm
group by convert(varchar(10),datepart(YYYY,a.fssj)),convert(varchar(10),datepart(mm,a.fssj))
order by convert(int,convert(varchar(10),datepart(YYYY,a.fssj))), --年份由字符串转化为数字
convert(int,convert(varchar(10),datepart(mm,a.fssj)))

posted @ 2015-01-23 17:24  樱花飞落ll  阅读(9574)  评论(0编辑  收藏  举报