Hi my table looks some what like this.
OldPart | NewPart | Demand
==========================
C | D | 3
F | | 1
A | B | 5
D | E | 2
E | F | 0
B | C | 3
Z | | 1
M | | 7
Y | Z | 10
What I am trying to do is come up with a final table where the newest part’s demand is aggregated and the demand for parts before it are changed to 0.
So my resulting table will be something like this:
OldPart | NewPart | Demand
==========================
C | D | 0
F | | 14
A | B | 0
D | E | 0
E | F | 0
B | C | 0
Z | | 11
M | | 7
Y | Z | 0
Thanks in advance.
Your mileage may vary, CTEs are limited. Out-of-the-box they only allow 100 steps deep. (I think the same goes for stored procs)
But … if you really want a recursive solution… something like this may work. (though it is not super efficient)
Keep in mind, loops and the like may throw this in to a spin.
results are:
Input is: