I wrote this tsql query, an SP that given a product code as input, calculates and prints on the screen the average value of the discount applied to the product in the sold. What can i do to automize(if is it possible) the @productid value given? And what can I do different in the code? The db is Northwind.
CREATE PROCEDURE dbo.StoredProcedureMean
AS
BEGIN
DECLARE @productid INT = 26
SELECT avg(Discount) FROM ProductDiscounted WHERE ProductID=@productid
END
or
ALTER PROCEDURE dbo.StoredProcedureMean
AS
BEGIN
DECLARE @productid INT = 26
SELECT avg(Discount) FROM ProductDiscounted WHERE ProductID=@productid
END
So, this is how I did till now, someone answer me if there something different I can do.