• Understood.

    You guys go ahead and call it whatever you want...that's the beauty of programming. I named it after the 2nd definition of "Tally" found here...

    http://education.yahoo.com/reference/dictionary/entry/tally

    ... which says...

    2.a. A stick on which notches are made to keep a count or score.

    ... stretching the definition a bit, it IS my computational "Tally" stick for reckoning what a loop would normally do. :hehe:

    Hey Joe... lot's of folks have made a "sequence" CTE such as what you say... would you mind posting yours? I've got one for Oracle (they call CTE's "Sub_Query Refactoring: in Oracle) at work that you might be interested in, as well. I'll post it tomorrow.

    In the meantime, if you have SQL Server 2005 and you want something that acts like a "Tally/Numbers/Sequence/Integers/IndexCount" table, here's a method that blows the doors off the recursive methods a lot of folks have come up with especially if it's called more than once... yes, I agree... it's non-portable code and I don't care... the Oracle method that I'll post tomorrow isn't either... I'm knowingly sacrificing portability for performance (like I usually do :P)...

    [font="Courier New"];WITH

    cteTally AS

    (--==== Create a Tally CTE from 1 to a desired count

     SELECT TOP (@DesiredCount)

            ROW_NUMBER() OVER (ORDER BY t1.Object_ID) AS N

       FROM Master.sys.All_Columns t1

      CROSS JOIN Master.sys.All_Columns t2

    )

     SELECT *

       FROM cteTally

    [/font]

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