• Evil Kraig F (11/28/2012)


    Alan.B (11/28/2012)


    Evil Kraig F (11/28/2012)


    This is NOT pretty, but it IS functional.

    I am trying to understand why went with a loop vs a set-based approach. I posted a more set based method earlier that gets the same results notably faster. I am not trying to be confrontational, I'm just trying to understand your approach or what I did wrong.

    Whoops, my apologies Alan. I didn't realize you were code complete. This comment:

    Alan.B (11/28/2012)


    This is a bit tricky and I am still working on this. Here's what I have thusfar...

    Misled me to believe you were still working on your solution and I breezed over it before going back to trying to force the rCTE to work.

    However, you will miss recursive chains. For example, I've adjusted the inclusion set here:

    INSERT #IDs VALUES (1,9), (1,10), (1,11), (2,11), (2,12), (3,12), (3,13), (4,14), (5,14)

    GO

    You'll notice that your code will no longer pick up Invoice 3 because You need to go from 1->2 via Booking 11, then 2->3 via Booking 12.

    Ahhhh.... Now I see what I was doing wrong; I knew I was missing something.

    Thanks & nice work.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001