CTE Replacement for Bi-Directional Recursion

  • Phil,

    I changed the procedure to create the index after the initial insert, but I had to immediately change it back. The while loop is controlled by @@ROWCOUNT. When the statement before was the initial insert of the root elements, then @@ROWCOUNT is set correctly. However if the statement right before the while is a create index, then @@ROWCOUNT is no longer valid and broke the recursion.

    Michael

  • michael.french 172 (6/14/2016)


    Phil,

    I changed the procedure to create the index after the initial insert, but I had to immediately change it back. The while loop is controlled by @@ROWCOUNT. When the statement before was the initial insert of the root elements, then @@ROWCOUNT is set correctly. However if the statement right before the while is a create index, then @@ROWCOUNT is no longer valid and broke the recursion.

    Michael

    I'm sure you know that that is only a minor issue.

    DECLARE @NumRows int;

    CREATE TABLE #RESULTS ...

    INSERT #RESULTS ...

    SET @NumRows = @@ROWCOUNT

    CREATE INDEX ...

    -- ... use @NumRows rather than @@ROWCOUNT

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Of course I should do that. I guess that what happens when I spend too much time converting PL SQL… and now back to your regularly scheduled cursor.

Viewing 3 posts - 16 through 17 (of 17 total)

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