Pepe Pepe - 8 months ago 32
SQL Question

MySql use 'LIKE' and 'IN' together

I have example table ExampleTable (Name and Code are varchare)

Name Code
test1 2016/554
test2 2016/13554
test3 2015/9893
test4 2015/74584

and i have working query in visual studio:
select * from [ExampleTable] where code LIKE '%' + '2016' + '%'

but I want do that user can define string which contains part of code. These parts are separate ','
Example: string = '2016,745'
and i want get test1,test2,test4

select * from [ExampleTable] where code LIKE IN (string with elements)

select * from [ExampleTable] where code LIKE '%2016%' or code LIKE '%745%';

this will do the job, and get answer as test1,test2,test4

use OR operator.