Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How do you handle underscore

$
0
0

Hi everybody,

I am wondering what approach do you take in handling underscore character in searches. Do you apply some special treatment and if yes, what is your approach.

Example:

declare @t table (email varchar(100))
insert into @t (email) values ('karen.todd@gmail.com'),('karen_todd@gmail.com')

declare @searchStr varchar(20) = 'karen_todd'

select * from @t where email like '%' + @searchStr + '%'

Even with the variable we're getting both rows as a result while we clearly intended to only find one row.

So, I am wondering as how do you normally treat this situation in your code. 

Thanks in advance.


For every expert, there is an equal and opposite expert. - Becker's Law


My blog


My TechNet articles


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>