日期:2014-05-17  浏览次数:20514 次

怎么获取sqlserver某张表中日期列里的日期并排序
table1里有两列,日期列和ID 列,我根据传进来的参数2012查与日期列相同的日期只有年分,获取了2012-1-12 10:15:00,
2012-2-12 10:15:00等许多,怎么把读到的数据的月份取出来并分组,如1,2,3,4,5,6。。。急急急,在线等

------解决方案--------------------
SQL code

declare @riqi int=2012
select convert(varchar(7),a.riqi,120),sum(b.[金额]) as total from table1 as a with(nolock) 
inner join table2 as b with(nolock) on a.id=b.id
where datepart(a.riqi)=@riqi
group by convert(varchar(7),a.riqi,120)