0

I have this query in SQL:

select cast(faturas.datatotal as date) as Dia, faturas.sumF, credito.sumC, isnull(sumF,0)-isnull(sumC,0) as Total
from
(SELECT       SUM([Line Amount]) as sumF, [Posting Date] as datatotal
                               FROM            [CMW$Sales Invoice Line] 
                               where [CMW$Sales Invoice Line].[Posting Date] >= '2017-01-01' 
                               group by [CMW$Sales Invoice Line].[Posting Date]) faturas                   
full outer join
(SELECT        SUM(Amount) as sumC, [Posting Date]
                               FROM            [CMW$Sales Cr_Memo Line] 
                               where [CMW$Sales Cr_Memo Line].[Posting Date] >= '2017-01-01' 
                               group by [CMW$Sales Cr_Memo Line].[Posting Date]) credito                           
on faturas.datatotal=credito.[Posting Date] 

I need to calculate the cumulative "Total" in this same query. How can I get this?

Fred
  • 11
  • 6
  • Can you copy and past your query to the question? – Serkan Arslan Nov 19 '17 at 18:15
  • Possible duplicate of [How to get cumulative sum](https://stackoverflow.com/questions/2120544/how-to-get-cumulative-sum) – Alex Kudryashev Nov 19 '17 at 18:53
  • I see that answer Alex, but I could not successfully apply it in my case ... I'm still starting myself in sql – Fred Nov 19 '17 at 19:32
  • Why could you not apply the answer linked by Alex? What error where you getting? Also, in future, a screen shot of code is very difficult to work with. It's better to put the actual text in so people can copy and paste – LordBaconPants Nov 19 '17 at 20:40
  • I have already changed to text instead of image. Maybe I was not able to use the answer suggested by my lack of knowledge in the area – Fred Nov 19 '17 at 22:26

1 Answers1

0

I solved my problem with this:

sum(isnull(sumF,0)-isnull(sumC,0)) over(order by faturas.datatotal rows unbounded preceding) as Acumulado

Thanks

Fred
  • 11
  • 6