title: Selecting total of child records in their respective parent records
body: <p>I have a table of chart of account with parent child relationship (hierarchy model).
  the table carry two types of accounts control accounts and transactional accounts.</p>
  
  <p>Transactional accounts have balances while they do not carry any child account.</p>
  
  <p>Control accounts do not have their own balances but they carry child accounts.</p>
  
  <hr>
  
  <pre>
  AccountID|     Title      |AccountType|ParentID| Balance
  ---------|----------------|-----------|--------|---------
   1       | Assets         |     c     |  null  | null 
   1-1     | Current Assets |     c     |  1     | null
   1-1-1   | Cash           |     t     |  1-1   | 1000
   1-1-2   | Inventory      |     t     |  1-1   | 2000
   1-2     | Fixed Assets   |     c     |  1     | null
   1-2-1   | Furniture      |     t     |  1-2   | 1500
   1-2-2   | Building       |     t     |  1-2   | 3000
  </pre>
  
  <hr>
  
  <p>i need a result set like :</p>
  
  <hr>
  
  <pre>
  AccountID|     Title      |AccountType|ParentID| Balance
  ---------|----------------|-----------|--------|---------
   1       | Assets         |     c     |  null  | 7500 --sum of current and fixed Assets
   1-1     | Current Assets |     c     |  1     | 3000 --sum of cash and inventory
   1-1-1   | Cash           |     t     |  1-1   | 1000
   1-1-2   | Inventory      |     t     |  1-1   | 2000
   1-2     | Fixed Assets   |     c     |  1     | 4500 --sum of furniture and building
   1-2-1   | Furniture      |     t     |  1-2   | 1500
   1-2-2   | Building       |     t     |  1-2   | 3000
  </pre>
  
  <hr>
  
  <p>Transactional Table</p>
  
  <hr>
  
  <pre>
  ID |AccountID|Amount
  ---|---------|------
   1 | 1-1-1   |  300  
   2 | 1-1-1   |  700
   3 | 1-1-2   | 1500
   4 | 1-1-2   |  500
   5 | 1-2-1   |  700
   6 | 1-2-1   |  800
   7 | 1-2-2   | 2000
   8 | 1-2-2   | 1000
  </pre>
  
  <p>Any select statement if possible
  or function or stored procedure.</p>
  
  <p>Any help Will be appreciated</p>