Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search Special character (%) in SQL Server 2008 [duplicate]

Tags:

sql

sql-server

I have a record with a value Jacj%25011987. I wanted to search the record with % as a character in a string.

I wanted to search this record using the Like in where clause.

I tried these queries, but they didn't work:

Select * 
From Table1 With (Nolock) 
Where Column1 like '%\%%'

Select * 
From Table1 With (Nolock) 
Where Column1 like '%'%%'

Thanks Parag

like image 223
rocky_pps Avatar asked Nov 09 '15 18:11

rocky_pps


People also ask

What is like %% in SQL?

The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters. The underscore sign (_) represents one, single character.


1 Answers

I think the easiest way is to use []:

where column1 like '%[%]%'

You can also use escape with whatever you like for the escape character:

where column1 like '%!%%' escape '!'

This is more portable, because ESCAPE is part of the ANSI standard.

like image 114
Gordon Linoff Avatar answered Nov 01 '22 06:11

Gordon Linoff