TechAid24

Your Technical Consultant

Tips for Searching Special Characters ( _ ) in SQL Server Columns

Posted on by Anonymous Guest 1 minute read

In this post, we want to discuss search underscore in columns in SQL Server. Before we get started, if you want to know about Merge Into command in SQL Server, please go through the following article: Using Merge Into in SQL Server.

This is done by adding the ESCAPE clause to your LIKE expression. The character that is specified with the ESCAPE clause will “invalidate” the following wildcard character. You can use any character you like (just not a wildcard character). Most people use a \ because that is what many programming languages also use in SQL Server.

So your query would result in:

SELECT * FROM Manager
WHERE managerid LIKE '\_%' escape '\'
AND managername like '%\_%' escape '\';

But you can just as well use any other character:

SELECT * FROM Manager
WHERE managerid LIKE '#_%' escape '#'
AND managername LIKE '%#_%' escape '#';

Tags:

Anonymous Guest

An anonymous author is a writer who conceals their true identity when publishing content, often for privacy, security, or confidentiality reasons. This approach is often used in technical articles to focus on the information being presented rather than the author's personal identity.

Leave a Reply

Your email address will not be published. Required fields are marked *