[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • 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

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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