This is what I have to exexcute
CREATE PROCEDURE sp_SalesByYr 1
. Parameter: OrderYear
2. Display the Total
sales for the Year
by territory
AdventureWorks2012
is the database.
- Sales.SalesOrderHeader table Sales
- Sales.SalesTerritory table
Here is my take: it results in an error code -
Must declare the scalar variable @Result
What is the remedy? (The datatype for the output should be Money rather than Integer)
CREATE PROC sp_SalesByYr
@OrderYear DateTime
AS
BEGIN
SET NOCOUNT ON;
SET (SELECT SUM(@SalesYTD) SalesByTy
FROM Sales.SalesOrderHeader a
WHERE a.OrderDate = @OrderYear
GROUP BY b.TerritoryID
)
END
DECLARE @Result Money
EXEC sp_SalesByYr '2002' OUTPUT
PRINT @Result