Answer the question
In order to leave comments, you need to log in
How to fulfill different conditions depending on the input parameter?
I want to execute different where depending on the input parameter?
CREATE PROCEDURE proc_IF (IN param1 INT)
BEGIN
SELECT * FROM articles
IF param1 = 0 THEN
WHERE name = 'Тест'
ELSE
WHERE name = 'Проверка'
END IF;
END
Answer the question
In order to leave comments, you need to log in
CREATE PROCEDURE proc_IF (IN param1 INT)
BEGIN
SET @query = CONCAT('SELECT * FROM articles ', IF(param1 = 0, " WHERE NAME = 'Тест';", , " WHERE NAME = 'Проверка';");
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question