Take the 2-minute tour ×

I have a database in Sql Server 2012 and there is a table like that

 ID | Date(date type) |  Amount(Numeric) 
  1      3.4.2013          16.00
  1      12.4.2013         13.00
  1      2.5.2013          9.50
  1      18.5.2013         10.00

I need to sum total amount for every month in a year.

For example:

  ID | Month |  TotalAmount
   1     1           0.00
   1     4          29.00
   1     5          19.50      

I tought need to determine the number of days in a moth and i created a function which is described in determine the number of days. It works. After that i tried to compare two dates(date type). There are some examples but all of them about datetime. So i am really stuck. Is it a wrong way ? How can i do that ? Pls give me any advice. Thx.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

I think you just want an aggregation:

select id, month(date) as "month", sum(amount) as TotalAmount
from t
where year(date) = 2013
group by id, month(date)
share|improve this answer
Awsome answer. Many thx.. –  Eyüp Alemdar Jul 4 '13 at 19:45

Your Answer


