0

How can I find the cumulative sum of ClosedIssueCount column? I have not been able to find the cumulative sum of this column.

Declare @FromDate DATE= '1/1/2016';
Declare @ToDate DATE='12/30/2016';
Declare @buid INT = 1;


with months (date)

AS

(

SELECT @FromDate

UNION ALL

SELECT DATEADD(month,1,date)

from months

where DATEADD(month,1,date)<=@ToDate

)


select distinct YEAR(Date) as years,
            MONTH(Date) as monnumber,
            [MonthName]    = DATENAME(mm ,Date) ,


--CloseIssueCount

((select count(distinct tbl_Issues.VulName) AS C
from tbl_Issues
inner join tbl_apptestdetails on tbl_Issues.testdetailid =   tbl_apptestdetails.testdetailid
inner join tbl_applicationlist on tbl_apptestdetails.appid = tbl_applicationlist.appid
inner join tbl_bu on tbl_applicationlist.buid = tbl_bu.buid
where tbl_Issues.Status=2   and DATENAME(mm ,Date) = DATENAME(mm ,tbl_Issues.CloseDt)  and tbl_bu.buid IN (@buid)
) )AS ClosedIssueCount







from  months
cross join tbl_apptestdetails 
inner join tbl_Issues outertbl_issues on tbl_apptestdetails.testdetailid = outertbl_issues.testdetailid
inner join tbl_applicationlist on tbl_apptestdetails.appid=tbl_applicationlist.appid
inner join tbl_bu on  tbl_bu.buid=tbl_applicationlist.buid
where tbl_bu.bustatus='Active' and tbl_bu.buid IN (@buid)
halfer
  • 19,824
  • 17
  • 99
  • 186
Ashu
  • 462
  • 3
  • 16
  • Which version of SQL-Server? – Shnugo Feb 03 '17 at 07:52
  • I am using 2008R2 – Ashu Feb 03 '17 at 07:59
  • Starting with SQL-Server 2012+ there is `SUM('SomeField) OVER(ORDER BY SomeOtherField)`, which is a fast implicit approach. With SQL-Server 2008R2 you'll find answers in the linked question. And for the next time please read [How to ask a good SQL question](http://meta.stackoverflow.com/questions/271055/tips-for-asking-a-good-structured-query-language-sql-question/271056) and [How to create a MCVE](http://stackoverflow.com/help/mcve) – Shnugo Feb 03 '17 at 08:03
  • Its Not Working – Ashu Feb 03 '17 at 08:08
  • Hi Ahsu, try to think with my head: Your question is absolutely unclear, no sample data, no expected output, not example of *this is wrong output and this is what I need*... The only thing you provide is *Its not working*. Not even a description of *what is not working?* Error messages, what ever... How do you think one could help you? – Shnugo Feb 03 '17 at 08:10

0 Answers0