• Sergiy (11/30/2015)


    Jason A. Long (11/30/2015)


    The other, less attractive, options are to use either a cursor or while loop.

    "Less attractive" is a questionable judgement. There were several tests here which proved that in terms of performance WHILE loop is more attractive than recursive CTE. It's not much, but faster. So, "the beauty is in the eyes of beholder" - if you have an antipathy to writing loops you may implement them in form of recursive CTE's.Some prefer everything to be "in a single query".But it's only an outlook.

    It's been my experience that recursive CTEs out perform both while loop and cursors. That said, there are always exceptions and the best way to know for sure in any given circumstance, is to write it both ways and see which version runs faster.