I need to make a stored procedure which takes supplierName, startDate and endDate as parameters and calculates the total income of that supplier for the given interval. I am using Northwind. The procedure looks as follows:
CREATE PROC usp_GetTotalIncomeByPeriod (
@companyName nvarchar(40),
@startDate date,
@endDate date)
AS
BEGIN
SELECT SUM(od.UnitPrice * od.Quantity * (1 - od.Discount))
FROM Orders o
JOIN [Order Details] od
ON o.OrderId = od.OrderId
JOIN Products p
ON od.ProductID = p.ProductID
JOIN Suppliers s
ON p.SupplierID = s.SupplierID
WHERE s.CompanyName = @companyName
AND (o.OrderDate BETWEEN @startDate AND @endDate);
END
GO
The problem is that I can't actually execute it using the following invokation:
EXEC dbo.usp_GetTotalIncomeByPeriod @companyName = 'Exotic Liquids',
@startDate = DATEFROMPARTS(1900, 01, 01),
@endDate = DATEFROMPARTS(2000, 1, 1);
The DATEFROMPARTS function seems to work fine on its own, but i cant manage to make it work as a parameter. It constantly gives me 'Incorrect syntax near 1900'. What do I miss?