Tim Cutting
Tim Cutting

Reputation: 327

Specify variable in a MySQL query

probably been asked before but I couldn't find an answer.

Is it possible to specify a user defined variable in a mySQL query. Such as:

select * from table where column like "%MYVAR%" or column like "%MYVAR%"

Basically, it would be a bit more complicated than that but if I wanted to use the same text multiple times how could I set this and reuse it?

Many thanks.

Upvotes: 0

Views: 154

Answers (2)

ivatanako
ivatanako

Reputation: 13

To get this working, you should use stored procedure. Check Documentation

Upvotes: 0

Devart
Devart

Reputation: 121902

It is possible -

SET @var1 = 'table%';
SELECT * FROM table1 WHERE column1 LIKE @var1;

More information - User-Defined Variables.

Upvotes: 5

Related Questions