SQL 'LIKE' query using '%' where the search criteria contains '%'

后端 未结 8 1936
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 02:29

I have an SQL query as below.

Select * from table 
where name like \'%\' + search_criteria + \'%\' 

If search_criteria = \'abc\', it will r

8条回答
  •  情深已故
    2020-12-03 03:08

    If you want a % symbol in search_criteria to be treated as a literal character rather than as a wildcard, escape it to [%]

    ... where name like '%' + replace(search_criteria, '%', '[%]') + '%'
    

提交回复
热议问题