• g.britton (11/21/2014)


    It's not just about efficiency, though cursors are usually the least efficient way to solve a problem.

    True, but not always true 😀

    Before windowing functions came through in SQL Server 2012, some problems could only be done using two ways:

    1. A lot of joining

    2. Using a cursor

    Number 1 is set-based, but scales quadratically in some cases. In other words, great for smaller sets, not so great for large sets.

    Number 2 is, well, a cursor, but it scales linearly. In other words, after a while it becomes better than the set-based approach. Until windowing functions showed up of course 😀

    There are some great examples in Itzik Ben-gans book about windowing functions.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP