I'd like my procedure to return the total of AcceptedProducts by PlantName.
Could someone help me to correct my procedure?
CREATE PROCEDURE spAcceptedByCountry @Year INT, @Month INT
AS
SELECT CountryCode,
CountryName,
REPLACE(SUBSTRING([PlantName], CHARINDEX('-', [PlantName]), LEN([PlantName])), '-', '') AS [PlantName],
SUM(AcceptedProducts) AS AcceptedProducts
FROM vAcceptedByCountry
WHERE YEAR(DateOfManufacture) = @Year AND MONTH(DateOfManufacture) = @Month
GROUP BY CountryCode,
CountryName,
PlantName,
AcceptedProducts
ORDER BY CountryCode;
GO
Thank you for your help. Kind Regards.