Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

order of LIKE values

Status
Not open for further replies.

AndyApp

Programmer
Dec 20, 2001
259
GB
I've got a search page and whatever the user puts in is subsequently built into a SQL statement in the LIKE clause. So if someone wants to search for "peter piper" my SQL looks like
Code:
LIKE '%peter%%piper%'
this is great however some of the entries are 'piper, peter' and the statement doesn't seem to bring these back. Is there a way to do this easily?
 
Not very useful but just for sport :eek:)
Code:
create table #t (field1 varchar(500))
insert into #t
select 'piper, peter' UNION ALL
select 'peter  piper'

select * from #t
where field1  LIKE '%[p][ei][tp][e][r]%'
drop table #t


Borislav Borissov
 
Remember that the like statement with a wildcard as the first character means the indexes cannot be used. When we have a requirement to do this kind of search, usually I search for the exact match first and then use the like search only if I get no records inthe exact search.

Questions about posting. See faq183-874
Click here to help with Hurricane Relief
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top