• Gary Harding (4/27/2015)


    Jeff Moden (4/26/2015)


    You're seriously aware of one of the more famous Pseudo-Cursors there is... a SELECT that uses a Tally Table.

    When I first saw this type of usage I thought it was black magic...

    DECLARE @Nums varchar(8000) = ''

    ;WITH T(n) AS (SELECT TOP(100) ROW_NUMBER() OVER (ORDER BY @@SPID) FROM sys.all_columns)

    SELECT @Nums += CAST(n AS varchar) + ','

    FROM T

    PRINT @Nums

    'Zactly. "Set Based Loop/Pseudo Cursor" tried and true.

    --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)