• jw.lankhaar (6/13/2013)


    For a limited number of rows (< 100) using a recursive common table expression is an alternative:

    Please read the following article for why you should probably never use an rCTE for such a thing.

    http://www.sqlservercentral.com/articles/T-SQL/74118/

    Note that due to recursion, the number of returned rows may not exceed 99.

    Careful now. It is true that the default for rCTEs is a max of 100 but that's easy to override using OPTION(MAXRECURSION x) where "x" can be any positive integer from 0 to 32,767 and "0" means "unlimited".

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)