• dwain.c (5/9/2012)


    ...Personally, I love playing with recursive CTEs, almost as much as I like being naughty, just to figure out how they work. ๐Ÿ˜›

    I always hear people saying "stay away from recursive CTEs because they're slow" ...

    Play is an excellent way to learn - I love to play with the problems folks post on here (far too little time these days). Here's a few examples of rCTE's to whet your appetite:

    Paul White's Super-fast DISTINCT

    Calculating interest rate

    Handshaking

    Running total with a twist

    Sequence-numbering groups

    Calculate volume percentages

    Have fun!

    Cheers

    ChrisM

    โ€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.โ€ - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden