I have this stored procedure
DELIMITER $$
USE `testdb`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `TestProcedure`(
IN year_number YEAR,
IN month_name VARCHAR(12),
IN input_region VARCHAR(20)
)
BEGIN
DECLARE total_regions_count INT DEFAULT 0;
## Get Distinct Regions.
SELECT
total_regions_count = COUNT(DISTINCT region)
FROM aws_cost AS AC
WHERE AC.year = year_number;
SELECT total_regions_count;
END$$
DELIMITER ;
When I call this stored procedure total_regions_count I get is 0 but when I execute the query directly, I get the correct count of distinct values (Which is 9 and not 0.).
Why is the variable returning me default value of the variable as the result? Why 9 is not getting returned?
I have tried INTO keyword also to set the value but still the same result.
SELECT COUNT(DISTINCT region) INTO total_regions_count ...