• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

underscore within like

when i use underscore, it seems like i am not getting predictable results.. can this be made reliable?
example:

declare @teststring table (testcolumn1 varchar(max)) 
insert into @teststring select 'Load PS.EMP TEST THIS COL: KEEP_EMP_SSN'
select * from @teststring
select * from @teststring where testcolumn1 like '%PS_EMP%'

Open in new window

0
25112
Asked:
25112
  • 2
  • 2
2 Solutions
 
Ephraim WangoyaCommented:

use this

LIKE '%PS[_]EMP%'
0
 
Ephraim WangoyaCommented:
The underscore is a wild card so to use it as a literal, you have to enclose it within square brackets  [_]
0
 
25112Author Commented:
wow.. so _ is just like %? (in a like statement)

anymore wildcard characters?
0
 
Kevin CrossChief Technology OfficerCommented:
Yes. '_' means any single character whereas '%' is multiple.
http://msdn.microsoft.com/en-us/library/ms179859.aspx
0
 
25112Author Commented:
cool...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now