I have an SQL query as below.
Select * from table where name like '%' + search_criteria + '%'
If search_criteria = 'abc', it will return data containing xxxabcxxxx which is fine.
xxxabcxxxx
But if my search_criteria = 'abc%', it will still return data containing xxxabcxxx, which should not be the case.
xxxabcxxx
How do I handle this situation?
If you want a % symbol in search_criteria to be treated as a literal character rather than as a wildcard, escape it to [%]
%
search_criteria
[%]
... where name like '%' + replace(search_criteria, '%', '[%]') + '%'
1.4m articles
1.4m replys
5 comments
57.0k users