Abhinav Singh
Abhinav Singh

Reputation: 263

SQL Searching a data containing '%'

How do we search Car%dinal using LIKE operator?

I am actually doing a search functionality on customer name where I am sending query from entity framework. So when I send car% in search box, it shows both rows. Because that will form a query like %searchstring%.

CustomerID  CustomerName    
92          Cardinal    
93          Car%dinal   

Upvotes: 0

Views: 95

Answers (1)

jarlh
jarlh

Reputation: 44776

Specify a LIKE escape character:

where CustomerName like '%car\%%' escape '\'

Or use INSTR() function:

where instr(CustomerName, 'car%') > 0

Upvotes: 8

Related Questions