Search for a string with _ in sql

2

I have to make a query against a table in a SQL Server 2014 database, the problem is that I have to search for the string _ _ _ (three followed without spaces / strong>, I put it that way because it edits it to me) and since the character _ is a wildcard when doing the search by LIKE %___% it does not return the desired results.

I would appreciate if someone can tell me how to do that search and not treat _ _ _ as a wildcard but as three _ followed and only remove those records where the field has _ _ _ anywhere in the chain.

Greetings.

    
asked by U. Busto 27.06.2017 в 11:56
source

1 answer

6

I just found something that could help you solve your problem, it's the search section wildcard characters in which he comments that there are two ways to specify a character that would normally be a wildcard:

The first would use the keyword ESCAPE to define an escape character. When the escape character is placed in front of the wildcard in a pattern, the wildcard is interpreted as a character. Example:

WHERE ColumnA LIKE '%/_/_/_%' ESCAPE '/'

The second would use brackets ( [ ] ) to include the wildcard character individually. Example:

WHERE ColumnA LIKE '%[_][_][_]%'
    
answered by 27.06.2017 / 12:09
source