I want to find string that have % character
For example, when one row's column has %%%%%,
SELECT * FROM table WHERE column LIKE '%value%';
If value is %, it returns all.
How can I search only that row?
I want to find string that have % character
For example, when one row's column has %%%%%,
SELECT * FROM table WHERE column LIKE '%value%';
If value is %, it returns all.
How can I search only that row?
You can use something like this to escape all %
characters in PHP:
$original_value = "%%%%%";
$temp = str_split($original_value, 1);
$escape_value = '\\'.implode('\\', $temp);
echo $escape_value;
Result (escaped value):
\%\%\%\%\%
Let’s say you want to find any fields that contain the text “100%”, so you put together this query:
Square Bracket Escape:
You can surround the % or _ with square brackets to tell SQL Server that the character inside is a regular character.
SELECT * FROM tablename WHERE fieldname LIKE ‘%100[%]%’
T-SQL ESCAPE Syntax:
Alternatively, you can append the ESCAPE operator onto your query, and add a \ character before the value you want to escape.
SELECT * FROM tablename WHERE fieldname LIKE ‘%100\%%’ ESCAPE ‘\’
The ESCAPE ‘\’ part of the query tells the SQL engine to interpret the character after the \ as a literal character instead of as a wildcard.
The easiest way is to include the characters I don't want, for example square brackets and slash:
SELECT * FROM Table
WHERE Name LIKE '%[\]\[/]%' ESCAPE '\'