Recursive CTE

  • Can someone explain how the below result arrives please ?

    with CTE(x)as

    (

    select x = 1

    union all

    select X=X+1 from CTE where x < 4

    union all

    select X=X+1 from CTE where x < 4

    )

    select x from CTE

    GO

    Result:

    x

    1

    2

    2

    3

    3

    4

    4

    4

    4

    3

    3

    4

    4

    4

    4

  • Please don't cross post. It just wastes peoples time and fragments replies.

    No replies to this thread please. Direct replies to: http://qa.sqlservercentral.com/Forums/Topic1099236-391-1.aspx

    Thanks
    Parthi

  • Edit: Moved here.


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • Yes Chris, appologies.

    I thought i had posted in the wrong category so posted under T-SQL too.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply