SQL Hierarchy and Sum on Same Table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • R2d2Rabeau
    New Member
    • May 2007
    • 21

    SQL Hierarchy and Sum on Same Table

    Hi,

    I am new to T-SQL, I am trying to fill-in a table with data already present in the table. The data to be used is located in type = C
    The problem is that the value in Type = B is the the sum of the Values of Type C but ONLY from the following rows AND until another type is encountered.
    (for exemple value in id = 2 is only 100 + 105 and in id = 5 it is only 79)
    Same principal applies for Type A but with the B values.
    The table looks like this:

    id type value
    1 A NULL
    2 B NULL
    3 C 100
    4 C 105
    5 B NULL
    6 C 79
    7 B NULL
    8 C 46
    9 C 23
    10 C 26
    11 A NULL
    12 B NULL
    13 C 126
    14 C 138
    15 B NULL
    16 C 149

    Can someone get me started with a code?
    I am stuck...

    Thank you for your help,
Working...