Question

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.

Était-ce utile?

La solution

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

SQL Fiddle Example

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top