Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 Add the row above..

Author  Topic 

VeselaApo
Posting Yak Master

114 Posts

Posted - 2010-11-15 : 16:55:08
Hi,

I have a table with two columns and am trying to create a formula in Column 1 , row 2 that will sum up Column 1 row 1 and Column 2 row 2. I want to continue the same formula down the column so that each row adds the row above it to the row next to it. How can i achieve this? what function?

Thanks much for your help!

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-11-16 : 00:45:48
You want to store the calculated value in a column.
One problem with this approach is that incase a middle row is deleted, it may not update the data for computed column in subsequent rows unless you write a trigger.

If possible you do the calculation before presenting the data to user.

What version of SQL you are using ?

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-16 : 03:20:18
Instead you can do it via SELECT statement

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

VeselaApo
Posting Yak Master

114 Posts

Posted - 2010-11-16 : 10:10:08
I am using Sql server 2005. can you please advise on the exact functions that you suggest to use? I am very unclear on how to approach this problem. thanks!
Go to Top of Page

VeselaApo
Posting Yak Master

114 Posts

Posted - 2010-11-19 : 19:32:51
quote:
Originally posted by madhivanan

Instead you can do it via SELECT statement

Madhivanan

Failing to plan is Planning to fail



Can you please specify how exactly I do this with select statement? thanks!
Go to Top of Page

namman
Constraint Violating Yak Guru

285 Posts

Posted - 2010-11-21 : 01:54:13

I think I misunderstand your question .... It is a bit unclear ...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-26 : 09:31:59
Post some sample data with expected result

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -