September 3, 2003 at 3:32 am
Hi ...
I've got a table with a column of quantities .I nedd to create a new column that acumulates these quantities up to the row in question.
Ex:
Qty Acumulation
-----------------
-----------------
1 1
3 4
6 10
I need to be able to save the acumulated value
Thanks
September 3, 2003 at 4:33 am
There are many solutions to most problems and of course you can use a cursor in this case. However another option depending on the size of your data is like so.
SELECT Qty,
(Qty + (SELECT SUM(Qty) AS OutX FROM tblData iq WHERE iq.Qty < oQ.Qty)) AS Acumulation
FROM tblData oQ
September 3, 2003 at 4:54 am
quote:
There are many solutions to most problems and of course you can use a cursor in this case. However another option depending on the size of your data is like so.SELECT Qty,
(Qty + (SELECT SUM(Qty) AS OutX FROM tblData iq WHERE iq.Qty < oQ.Qty)) AS Acumulation
FROM tblData oQ
to piggy-back on this answer, I really think this is more a presentational problem.
Do you really need to store these values in your table?
Cheers,
Frank
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply