Pregunta

Is it possible to create a variable in MySql for a LIKE expression?

ex.

SET @test = '%my text to look for%';
SELECT * FROM MYTABLE WHERE MYCOLUMN LIKE @test;

Of course I tried this approach and it did not work.

Sorry for choosing the mysql-connect tag, couldn't really come up with anything else.

EDIT 1

"Did not work" means I don't get results with the variable as without.

¿Fue útil?

Solución

Yes, your example should work fine. See my test case below:

SQL Fiddle Example

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top