码迷,mamicode.com
首页 > 数据库 > 详细

sqlserver 取日期年份月份

时间:2015-01-23 17:56:27      阅读:424      评论:0      收藏:0      [点我收藏+]

标签:

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 取日期年份月份

标签:

原文地址:http://www.cnblogs.com/miraclesakura/p/4244710.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!