SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to exclude wildcards in a like search
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nelsont
Starting Member

USA
25 Posts

Posted - 12/06/2012 :  17:43:42  Show Profile  Reply with Quote
I know how to escape individual wildcard characters when doing a search using 'like'. I need to search a column in a table using a string that is input from the user that may contain one or many wildcard characters.

Other than surrounding the incoming string with Replace commands for each possible wildcard, is there an easier way to do this?

srujanavinnakota
Starting Member

34 Posts

Posted - 12/06/2012 :  19:08:34  Show Profile  Reply with Quote
Try CHARINDEX
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 12/07/2012 :  08:12:11  Show Profile  Reply with Quote
why do you need separate REPLACE statements? wont a single REPLACE be enough for all wildcard characters?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

nelsont
Starting Member

USA
25 Posts

Posted - 12/08/2012 :  23:46:40  Show Profile  Reply with Quote
Can either of you show at least a simple example?
Go to Top of Page

DonAtWork
Flowing Fount of Yak Knowledge

2161 Posts

Posted - 12/10/2012 :  10:41:51  Show Profile  Reply with Quote

declare @yak varchar(20)

select @yak = 'sier*#@kjf(*#@$ljh'

select @yak

While PatIndex('%[!@#$%^&*()]%', @yak) > 0
    Set @yak = Stuff(@yak, PatIndex('%[!@#$%^&*()]%', @yak), 1, '')

select @yak









How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000