/* GET THE SCORE WEIGHT FOR SPECIFIC CATEGORY */
/* =============================================================================================================== */
DROP FUNCTION IF EXISTS GET_SCORE_WEIGHT;
COMMIT;

delimiter //

CREATE FUNCTION `GET_SCORE_WEIGHT`(`p_category` varchar(255))
RETURNS INT
BEGIN

	DECLARE iWeight INT DEFAULT NULL;
	
	SET iWeight = (
    SELECT `weight`
    FROM `HealthScoreWeights`
    WHERE `category` = p_category
    AND `isActive` = 1
  );

  IF iWeight IS NULL THEN
    SET iWeight = 0;
  END IF;
	
	RETURN iWeight;

END 
//
COMMIT //

delimiter ;
