[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

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