a example with real data:
CustomerId Scope Key Value
1 Customer SelfPasswordReset_MaxAttempts 5
2 Customer SelfPasswordReset_MaxAttempts 10
3 Customer SelfPasswordReset_MaxAttempts 20
NULL Platform PlatformGUID c20414f6-3bd2-4d37-ac74-152b0efdb582
...
assume we further have a CustomerParant table
CustomerId ParentId Level
5 5 0
5 1 1
4 4 0
4 2 1
4 1 2
3 3 0
3 2 1
3 1 2
2 2 0
2 1 1
1 1 0
listing the parents of every customer and how much iterations you need to traverse through the tree to arrive there. means 3's parent is 2, 2's parent is 1 etc...
Now i want to build a query that returns a result like this:
CustomerId SelfPasswordReset_MaxAttemps PlatformGUID ...
5 5 c20414f6-3bd2-4d37-ac74-152b0efdb582
4 10 c20414f6-3bd2-4d37-ac74-152b0efdb582
3 20 c20414f6-3bd2-4d37-ac74-152b0efdb582
2 10 c20414f6-3bd2-4d37-ac74-152b0efdb582
1 5 c20414f6-3bd2-4d37-ac74-152b0efdb582
Special Note: Not every customer has his level defined. as you see i added customer 4 and 5 who don't have data a parameter defined of their own. they will inherit from their parent instead