Barry Barry - 4 months ago 7
SQL Question

Use Variable For IN Operation

How to use the following variable content for an IN query...

SET @var = '1,2,3';
SELECT * FROM Table WHERE ID IN (@var);

Answer

Solution was found by looking at this answer

SET @var = '1,2,3';
SET @Expression=CONCAT('SELECT * FROM TableWHERE ID IN (',@var,')');
PREPARE myquery FROM @Expression;
EXECUTE myquery