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 2005 Forums
 Transact-SQL (2005)
 LIKE query with table of wildcard strings

Author  Topic 

ChrisDeyloff
Starting Member

1 Post

Posted - 2008-03-07 : 23:21:53
The sql below is a simple example of LIKE query with a table of wildcard strings. I hope this helps others.

declare @LikeTable Table
(
LikeValue nvarchar(50)
)

insert into @LikeTable (LikeValue) values ('%blah')
insert into @LikeTable (LikeValue) values ('%abc%')
insert into @LikeTable (LikeValue) values ('%edf%')
insert into @LikeTable (LikeValue) values ('car%')
insert into @LikeTable (LikeValue) values ('%ome%')

declare @CompareValue nvarchar(50)
set @CompareValue = 'some value'

select * from @LikeTable where (@CompareValue like LikeValue)

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-08 : 10:31:13
Great!

You want to search predefined search values from a table of predefined search values.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-03-13 : 06:28:14
So % should be part of data?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-13 : 06:44:30
Please move topic out of SCript Library.


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

KenW
Constraint Violating Yak Guru

391 Posts

Posted - 2008-03-13 : 16:33:19
We need a new forum. Maybe something like "Bad SQL Ideas and Techniques"?
Go to Top of Page
   

- Advertisement -