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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Cursor Vs Set operations

Author  Topic 

ALBean
Starting Member

12 Posts

Posted - 2004-05-28 : 12:02:19
Right now I’m using a cursor to do something. But I have been reading the postings on this website and I am wondering if there is a way to do my calculation with set based operations.

I would like to go threw an order set of rows and take a value from the row immediately above the current row, do a calculation on that value and then update the value in the current row with the result. (The very first row will be initialized).

For example:
Initial set:
A 1
B 0
C 0
D 0

Final Set (calculation: currentRow = rowAbove*2 )
A 1
B 2
C 4
D 8

(After I get the value in row A, I use a cursor and loop threw rows B to D) Can this be done with an SQL set statement?

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-05-28 : 12:26:54
Calculating Running Totals

Jay White
{0}
Go to Top of Page

ALBean
Starting Member

12 Posts

Posted - 2004-05-28 : 12:48:05
Thanks Jay,

I guess I will stick with my cursor implementation since it appears to be faster in this case.
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-05-28 : 13:31:55
No, I think the point of the article is that the performance is very dependent on your particular data set. I'd recommend doing some tests agains each of the methods.

Jay White
{0}
Go to Top of Page
   

- Advertisement -