/* CHECK IF A USER HAS MED BUDDIES */
/* =============================================================================================================== */
DROP FUNCTION IF EXISTS USER_HAS_BUDDIES;
COMMIT;

delimiter //

CREATE FUNCTION `USER_HAS_BUDDIES`(`p_userId` varchar(36))
RETURNS TINYINT
BEGIN

	DECLARE tHasBuddies TINYINT;
	
  SELECT COUNT(*) > 0
  FROM `MedBuddies`
  WHERE `userId` = p_userId
  AND `status` = 'active'
  INTO tHasBuddies;
	
	RETURN tHasBuddies;

END 
//
COMMIT //

delimiter ;
