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)
 Whole Word Search

Author  Topic 

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2001-08-29 : 14:18:17
OK, this time I've been a good boy and have been searching and reading BOL and this site. I'm trying to avoid using a Full-Text index (perception of extra overhead to maintain), unless convinced otherwise. Is there a decent way to do a "match whole-word only" search using LIKE statements? Here's a sample:


CREATE TABLE #TestSearch (
StoryID int IDENTITY,
Body varchar(200)
)
GO
SET NOCOUNT ON
INSERT INTO #TestSearch (Body) VALUES ('This is a story about a cat.')
INSERT INTO #TestSearch (Body) VALUES ('The mayor categorically denied that he was drunk at Mardi Gras.')
INSERT INTO #TestSearch (Body) VALUES ('I once had a dog.')
INSERT INTO #TestSearch (Body) VALUES ('Your cat makes me sneeze.')
INSERT INTO #TestSearch (Body) VALUES ('Cats think they rule the world, but a dog is always glad to see you.')
GO
SET NOCOUNT OFF
GO

SELECT * FROM #TestSearch WHERE Body LIKE '% cat %'
GO

DROP TABLE #TestSearch
GO


The problem is that the word may be at the beginning, end, or have punctuation around it. I don't really want to do a gazillion OR LIKE statements. Ideally, the solution would return stories 1 and 4 (5 would also be nice) but skip 2 and 3.

Any ideas? (SQL 7, NT4, ASP front-end)

------------------------------------------------------------------
Contractor$ never die, they just leave for higher-paying project$.
   

- Advertisement -