You cannot use an IN clause like this. It compiles to a single string in your IN clause. But the IN clause requires separate values.
WHERE id_campo not in (@idcamposexcluidos)
compiles to
WHERE id_campo not in ('817,803,495')
but it should be
WHERE id_campo not in ('817','803','495')
To overcome this or use dynamic SQL or MySQL, you can use FIND_IN_SET :
SET @idcamposexcluidos='817,803,495'; ... WHERE FIND_IN_SET(id_campo, @idcamposexcluidos) = 0
juergen d Aug 14 '12 at 17:35 2012-08-14 17:35
source share