Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Recursive query on table variable - bottom to top.

$
0
0

Hi All,

 

This is an awkward question, and I really first want to know how viable this is to do in SQL 2005. If it is viable then suggestions on how to approach this.

 

I have a recursive query that populates a temporary table with multiple headings. Each of these headings has children and there is the idea of a parent child relationship to identify how different headings are nested below each other. There is one root node but the number of levels is not the same for each path through the nested headers,

 

What i need to do is to forst of all populate a value field in the leaf nodes in of the table (i.e. the ones at the bottom of each path). Once these are populated i then need to set the value of the parent of these nodes to the sum of its direct children. In addition to this i need to check the database tables where i get the leaf values and see if there are any values for the current parent. If there is a value then i need to add this to the value already calculated.

 

For each node in the parent child relationship i need to do this and i have no idea as to how to begin, Anything I have done recursively using CTE's has been from the top down and not over multiple differing depth paths.

 

I've hopefully explained the problem at least well enough for someone to vaguely understand what i'm trying to do. If anyone can provide any suggestions they'd be greatfully recieved.

 

Thanks in advance,

 

G


Viewing all articles
Browse latest Browse all 23857

Trending Articles