Reputation: 1776
i have a table Stock with
StockID ItemID Quantity Price
now i want to select data some thing like this
StockID ItemID Quantity Price TotalPrice(Quantity*Price)
i tried this
ALTER PROC [dbo].[SelectItemStock]
@Item int
as
BEGIN
SELECT Stock.*, (SELECT Quantity*Price FROM Stock) AS TotalPrice
FROM Stock
WHERE ItemID = @Item
END
but it gives me the error Subquery returned more than 1 value.
Please help me to solve this problem
Upvotes: 1
Views: 3395
Reputation: 263803
you don't need to do a subquery to get the product of the two columns, just multiply it directly,
ALTER PROC [dbo].[SelectItemStock]
@Item int
as
BEGIN
SELECT Stock.*,
(Quantity*Price) AS TotalPrice
FROM Stock
WHERE ItemID = @Item
END
Upvotes: 7