Use:
SELECT oi.orderid,
SUM(oi.quantity * p.price) AS grand_total,
FROM ORDERITEM oi
JOIN PRODUCT p ON p.id = oi.productid
WHERE oi.orderid = @OrderId
GROUP BY oi.orderid
Mind that if either oi.quantity
or p.price
is null, the SUM will return NULL.
OMG Ponies
2010-08-17 19:49:19