• djj (6/23/2015)


    sgmunson (6/22/2015)


    djj (6/22/2015)


    Thank you ChrisM@Work, I will not be changing the code now that I have conformation of what it does.

    It's always good to understand what code does before you change it, and one of the best ways to understand is to change the DELETE statement into a SELECT and see what records are returned. If a change is planned, create a copy of the code to make changes to, and then change DELETE to SELECT and see if it returns the exact same records as the original code with the change from DELETE to SELECT. If it does, and the logic of the changed query appears to duplicate the logic of the original, then you are probably good to go.

    In this case I new what the delete did and what the cte returned so the select would not have helped with my understanding that the cte table is directly connected (pass through) to the underlying table. I had thought a cte table was more like a temporary table containing data but not connected directly to the table it came from.

    As stated I personally would have programmed something like you suggested. As to changing the current code, it comes down to we have too many higher priority projects going for me to get a review for a code change that is not needed. I will keep it on my "possible to do" list.

    Thanks everyone for the discussion, I am always learning.

    Think about the CTE as if it were a view. You can update a view, and from that perspective, a CTE works very much the same way.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)