Tuesday, February 28, 2006

The Cursor is Dead! Long Live the Cursor!

Adam Machanic is one of my favorite MVPs - I like his books, he's always willing to help in the newsgroups, he speaks well at the conferences, and when he has an opinion, I pay attention.

SQL Server 2005 Bible will have a chapter called "Kill the Cursor!" that works through a complex logic problem and solves it 7 different ways - 4 cursors and 3 set-based solutions. For complex logic, set-based solutions rule; but not so for cumulative totals.

In some text for a future publication, a tech reviewer disagreed with me when I said that cumulative totals (running sums) were best done with a cursor. The tech reviewer listed what appears to be an elegant correlated subquery that does in fact do running sums. The assumption was that set-based was always faster than a cursor.

Adam was on the thread and volunteered to run the tests...
Adam's Blog

0 Comments:

Post a Comment

<< Home