Solved

underscore within like

Posted on 2011-09-08
5
299 Views
Last Modified: 2012-05-12
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
Comment
Question by:25112
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 36507328

use this

LIKE '%PS[_]EMP%'
0
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 300 total points
ID: 36507338
The underscore is a wild card so to use it as a literal, you have to enclose it within square brackets  [_]
0
 
LVL 5

Author Comment

by:25112
ID: 36507409
wow.. so _ is just like %? (in a like statement)

anymore wildcard characters?
0
 
LVL 60

Assisted Solution

by:Kevin Cross
Kevin Cross earned 200 total points
ID: 36507573
Yes. '_' means any single character whereas '%' is multiple.
http://msdn.microsoft.com/en-us/library/ms179859.aspx
0
 
LVL 5

Author Comment

by:25112
ID: 36507769
cool...
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question