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.

Was it helpful?

Solution

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

SQL Fiddle Example

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top