2

I am trying to query Keyword 100% using Like command.

LIKE (‘%100%%’) 

But the command is querying for all keywords with 100 which is not what I want

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 3
    Possible duplicate of [SQL 'LIKE' query using '%' where the search criteria contains '%'](https://stackoverflow.com/questions/10803489/sql-like-query-using-where-the-search-criteria-contains) – Ajay Chaudhary Apr 08 '19 at 04:58

2 Answers2

2

Use Escape Character. Try:

Select * from MyTable m where m.Column1 like '%100\%%' escape '\'

Escape Character can be set as per your convenience.

In the above query, replace MyTable with your table name and Column1 with your Column Name.

Habeeb
  • 7,601
  • 1
  • 30
  • 33
1

You could also take advantage of SQL Server's LIKE operator's regex syntax, and use [%] to represent a literal percent:

SELECT *
FROM yourTable
WHERE col LIKE '%100[%]%';

Demo

I prefer this method to the accepted answer because it makes more explicit the intention to represent a literal character, and it avoids the possible need for an ESCAPE clause.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360