Search code examples
sqlsql-serverasp-classicjet

ASP Classic SQL query to get cumulative ammounts per day


I am struggling with a SQL query I have a collection process and I want to have a query that show me every day how much we have collected so far during the current month in a cumulative way. I have all the information in one table named Procesado the date field is Process Date and the amount is in lcamnt Field.

So far I have this:

Query:

SELECT 
    Procesado.ProcessDate, SUM(Procesado.lcamnt) AS Monto 
FROM 
    Procesado 
WHERE 
    Procesado.ProcessDate >= Procesado.ProcessDate 
GROUP BY 
    Procesado.ProcessDate

Table value

Table Name: Procesado

ProcessDate  lcamnt  
05/26/2016   $1000  
05/26/2016   $500  
05/27/2016   $2000  
05/27/2016   $1000  
05/28/2016   $5000  

Desired output

05/26/2016   $1500  
05/27/2016   $4500  
05/28/2016   $9500  

Solution

  • select p.ProcessDate,
           (select sum(lcamnt)
            from procesado p2
            where 
                  p2.ProcessDate <= p.ProcessDate
           ) as Monto
    from  procesado p
    group by p.processDate