I have to perform a query against a table of a SQL Server 2014 database , the problem is that I have to search for the string _ _ _ (three in a row without spaces , I put it like this because it edits it for me) and since the character _ is a wildcard when doing the search for LIKE %___%
does not return the desired results.
I would be grateful if someone could tell me how to do that search and not treat _ _ _ as a wildcard but as three _ in a row and only get those records where the field has _ _ _ anywhere in the string.
All the best.
I just found something that could help you solve your problem, it is the search for wildcards section in which it comments that there are two ways to specify a character that would normally be a wildcard:
The first would be to use the keyword
ESCAPE
to define an escape character. When the escape character is placed before the wildcard in a pattern, the wildcard is interpreted as a character. Example:The second would be to use square brackets (
[ ]
) to enclose the wildcard character individually. Example: