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 2000 Forums
 SQL Server Development (2000)
 Wildcard Search in SQL

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-04-15 : 07:40:53
Sean writes "Hi,

I have the following search query that looks through a product catalog for any words that match the entered word (RsDetails_varSearch):

SELECT * FROM dbo.Products WHERE [Price Sheet Description] LIKE '" + Replace(RsDetails__varSearch, "'", "''") + "%' OR [Price Sheet Description] LIKE '%" + Replace(RsDetails__varSearch, "'", "''") + "' OR [MAS DESCRIPTION] LIKE '" + Replace(RsDetails__varSearch, "'", "''") + "%' OR [Long Description] LIKE '" + Replace(RsDetails__varSearch, "'", "''") + "%' OR keywords LIKE '" + Replace(RsDetails__varSearch, "'", "''") + "%' and [Ready to Publish] = 1"

My question is this: I want the search query to find partial words, multiple words or if part of a word exists in the database to grab it in my results set.

Thanks for the help in advance,

Sean

P.S. I know this is why Inktomi and Google make big bucks, but a search like this would be helpful."

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2003-04-15 : 08:11:19
Have you considered Full-Text search?

Jay White
{0}
Go to Top of Page

skillile
Posting Yak Master

208 Posts

Posted - 2003-04-16 : 23:33:03
It will depend on the search word but your like query should contain

'%' + @var + '%'

If you need sounds like or more fuzzy then use full text.

slow down to move faster...
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2003-04-17 : 12:25:51
Here are two good articles on the subject. I have implimented the first method, and it works great! I think the first method is what you are looking for. The part where he has 3 INSERT statements, you'll need several there to handle all of the fields you want and all of the different ways you want to search. I suggest looking into SOUNDEX() in BOL. That's an interesting way to suppliment a "LIKE" search.

http://www.sqlteam.com/item.asp?ItemID=1876

http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm

Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page
   

- Advertisement -