Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to exclude wildcards in a like search

Author  Topic 

nelsont
Starting Member

25 Posts

Posted - 2012-12-06 : 17:43:42
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 - 2012-12-06 : 19:08:34
Try CHARINDEX
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-07 : 08:12:11
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

25 Posts

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

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-12-10 : 10:41:51
[code]
declare @yak varchar(20)

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

select @yak

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

select @yak
[/code]








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

Go to Top of Page
   

- Advertisement -