Example My cursor Parent ID ChildID UsedQty A01 Z01 7 Z01 X01 5 X01 Y01 8 A01 contains 7 pcs of item Z01. Z01 contains 5 pcs of item X01. X01 contains 8 pcs of item Y01. I need to calculate the current qty of each item which, Current Item Qty Before Deducted -------------------------------- ItemID Qty A01 10 Z01 2 X01 12 Y01 6 Expect Result ItemID Qty A01 10 Z01 2 - (10* 7) X01 12 - ( 2* 5) Y01 6 - (12* 8)How to qrite SQL to make it?