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
2024-01-21 18:43:22
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