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)
 Search key word in whole word not partial word

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2007-08-15 : 08:54:37
If I use "...like %work%" to search "Work" only may come out "network", "workable"...
How to code to search whole word not partial word?

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2007-08-15 : 09:11:17
use col1 = 'Work' , the '%' is a wildcard so 'Work%' gives workable, workout, etc. and '%work' gives network,homework, etc.

Jim
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-08-15 : 09:14:52
[code]SELECT *
FROM
(
SELECT word = 'work' UNION ALL
SELECT word = 'workable' UNION ALL
SELECT word = 'working' UNION ALL
SELECT word = 'homework' UNION ALL
SELECT word = 'networking'


) w
WHERE ' ' + w.word + ' ' LIKE '% work %'[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -