Here is my data
date amount
2017-07-10 15.00
2017-07-10 15.00
2017-07-28 25.00
2017-08-01 100.00
2017-08-12 15.00
2017-08-29 200.00
2017-09-18 105.00
2017-09-21 200.00
2017-09-23 25.00
2017-10-12 15.00
2017-10-14 500.00
2017-11-01 200.00
2017-11-02 200.00
I want to add it by month so what we will get that in June i got a total of 55, August i will get 315, September 330, October 515, November 400 and the past dates with no amount will be 0 how will i do that?
Here is my temporary table codes:
create table #TempTable
(month varchar(50),
amount decimal(18,2))
insert into #TempTable (month)
SELECT TOP 12
DATENAME(MONTH, DATEADD(MONTH,ROW_NUMBER() OVER (ORDER BY object_id) - 1,0))
FROM sys.columns
create table #Data
(date date,
amount decimal(18,2))
insert into #Data(date,amount) values('2017-07-10',15.00)
insert into #Data(date,amount) values('2017-07-10',15.00)
insert into #Data(date,amount) values('2017-07-28',25.00)
insert into #Data(date,amount) values('2017-08-01',100.00)
insert into #Data(date,amount) values('2017-08-12',15.00)
insert into #Data(date,amount) values('2017-08-29',200.00)
insert into #Data(date,amount) values('2017-09-18',105.00)
insert into #Data(date,amount) values('2017-09-21',200.00)
insert into #Data(date,amount) values('2017-09-23',25.00)
insert into #Data(date,amount) values('2017-10-12',15.00)
insert into #Data(date,amount) values('2017-10-14',500.00)
insert into #Data(date,amount) values('2017-11-01',200.00)
insert into #Data(date,amount) values('2017-11-02',200.00)
select * from #Data
select * from #TempTable
drop table #TempTable
drop table #Data
PS. Just update the #TempTable and put the total on it thank you :)