Answer the question
In order to leave comments, you need to log in
How to fix the function?
help me create a function
to be honest in mysql this is my first time doing this
CREATE DEFINER = CURRENT_USER FUNCTION `GetMailAcc`(`in_domen_id` int)
RETURNS varchar(255)
BEGIN
DECLARE result_str VARCHAR(255);
SELECT COUNT(1) AS result_id FROM L_mail_account AS MA WHERE MA.domen_id = in_domen_id LIMIT 1;
IF result_id > 0 THEN
SELECT id FROM L_mail_account ORDER BY last_upd DESC LIMIT 1;
ELSE
SELECT MA.id FROM L_mail_account AS MA WHERE MA.domen_id = in_domen_id LIMIT 1;
END IF;
RETURN id;
END;
Answer the question
In order to leave comments, you need to log in
the issue was resolved by passing the value to the variable
CREATE DEFINER=`root`@`%` FUNCTION `GetMailAcc`(`in_domen_id` int) RETURNS int(11)
BEGIN
DECLARE result_str, count_str INT(11);
SET count_str = (
SELECT COUNT(1) AS QTY
FROM L_mail_account AS MA
WHERE MA.domen_id = in_domen_id
ORDER BY last_upd DESC
LIMIT 1
);
IF count_str > 0 THEN
SET result_str = (SELECT MA.id FROM L_mail_account AS MA WHERE MA.domen_id = in_domen_id LIMIT 1);
ELSE
SET result_str = (SELECT id FROM L_mail_account ORDER BY last_upd DESC LIMIT 1);
END IF;
RETURN result_str;
END
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question