• siddharthak024 (11/29/2015)


    My question is how to solve it, Please don't divert the issue. I have to use the non cte code in different places.

    As Jeff alluded, this is one of those instances where the recursive CTE is the best option. The other, less attractive, options are to use either a cursor or while loop.

    Considering that you don't consider CTEs to be "normal"... I don't imagine that you'd consider loops & cursors to be normal either... In which case, you're SOL...

    If you have the option to add columns to your table, you could also consider the use of "nested sets". This would, of course, alleviate for loops or recursion when querying the data, but you'd still need them to populated the left & right bowers.