Click here to Skip to main content
14,669,424 members
Rate this:
Please Sign up or sign in to vote.
See more:
pls how can i achieve this using a view
i have this table A

month |amt
Jan 10
Feb 20
Mar 12
apr 34

I want this in a veiw like this

month |amt |Acumulated amt
Jan 10 10
Feb 20 30
Mar 12 42
apr 34 76

how do i add from the first month comming down to the last month an showing each Acummulated amt
i have used this code in a view but it does no work
SELECT DISTINCT MONTH, Amt, Amt + Amt AS bb
FROM         dbo.A
WHERE     (MONTH <= MONTH)
ORDER BY MONTH<code></code>
Posted
Updated 9-Feb-13 21:52pm
v6

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Look at this article on running totals.

http://geekswithblogs.net/Rhames/archive/2008/10/28/calculating-running-totals-in-sql-server-2005---the-optimal.aspx[^]

You need to really to do self joins. Basically reference your table twice, and link on the month where table a month is less than table b month and add a and b amount together.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100