Is it possible to search for a row or rows with particular strings containing an underscore?
Suppose I have various email addresses all containing an underscore like email@example.com, hj_bus@ where.com, etc.How can I search for those particular emails?
If I use a WHERE clause such as 'WHERE eMail LIKE '%_' it returns all rows. 'WHERE eMail LIKE 'gm_%' returns rows that do not contain an underscore. Can you offer any suggestions?
The underscore character is a single character wildcard in the same way the percent sign is a multi-character wildcard. To query for an underscore character you need to wrap the underscore in square brackets:
WHERE email LIKE 'gm[_]%'
If you want to search for all email addresses with a two character value then an underscore, this WHERE clause would work:
WHERE email like '__[_]%@%'
Dig Deeper on Microsoft SQL Server Performance Monitoring and Tuning
Related Q&A from Denny Cherry
If you have exceptionally large SQL Server databases, refer to these best practices for proper database maintenance to steer clear of a website '... Continue Reading
Discover a tool that synchronizes two SQL Server databases allowing changes to one SQL Server database to update on the other. Continue Reading
Troubleshoot long running stored procedures with SQL Server Profiler by adding events to find the command with high run time. Continue Reading