首页 > 代码库 > sqlserver 取日期年份月份

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)))

sqlserver 取日期年份月份