SELECT COALESCE(SUM((price/priceper)*QtyRequired),0) as total_value,
COALESCE(SUM((price/priceper)*QtyRequired),0) as outstanding_value
FROM @Item i
LEFT OUTER JOIN @OrderItem o ON i.Id = o.ItemId
WHERE i.Id = @ItemIdTest
group by itemId
原文:http://www.cnblogs.com/damoco/p/4015750.html