Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
dungla
Starting Member
2 Posts |
Posted - 2008-09-10 : 00:32:41
|
| Hi Experts,I've 2 tables below:Table1MyIDParentID (Self link to MyID)Code=====Table2 (store value of smallest level item in Table1, the item that doesn't has any child)MyIDValue=======I've succeed query a hierarchy view of Table1. Now I want to add value from Table2 to the query associated with MyID from Table1. The value will be roll up to parent value.Example:Table1MyID ParentID Code1 NULL First2 NULL Second3 1 Third4 3 Fourth5 3 Fifth6 1 Sixth7 2 SeventhTable2MyID Value4 105 206 307 40Result should be:MyID Value1 60--3 30----4 10----5 20--6 302 70--7 40The question is: How can I roll up value from child to parent in hierarchy view?LAD |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-09 : 03:07:00
|
Use a recursive Common Table Expression (cte). E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|