I have two tables as follows
PRODUCT table
PRODUCT
Id | Name | Price
And an ORDERITEM table
ORDERITEM
Id | Orde
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.
oi.quantity
p.price