Welcome to Dream.In.Code
Become an Expert!

Join 149,489 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,291 people online right now. Registration is fast and FREE... Join Now!




Find word in db field

 
Reply to this topicStart new topic

Find word in db field

fyrestorm
30 Mar, 2007 - 04:27 PM
Post #1

D.I.C Lover
Group Icon

Joined: 4 Apr, 2002
Posts: 3,103



Thanked: 2 times
Dream Kudos: 228
My Contributions
I want to have a sql query that will check if a word is in the field

I.E.
CODE
SELECT * FROM tbl WHERE field (contains) 'test'


I'm having problems with the (contains) part. I don't want to put wildcards around 'test' because I don't want variations of test (such as tested, testing) to show up in my search results.

Any help would be greatly appreciated.
User is offlineProfile CardPM
+Quote Post

cyberscribe
RE: Find Word In Db Field
30 Mar, 2007 - 04:34 PM
Post #2

humble.genius
Group Icon

Joined: 5 May, 2002
Posts: 1,062



Thanked: 2 times
Dream Kudos: 154
My Contributions
well,

CODE

select * from myTable where myField like ('% test %')


would give you all instances of the word test where it appears in the middle of a sentence. The problem with putting it just after the word is it will also match 'contest' and, as you said, with a space before the word it will match 'tested'. But with spaces on either side, it won't match 'Test' at the end of a sentence. You may be able to do some wildcard matching to account for 'test.' (and all its variants like 'test!' and 'test?') but I haven't played much with pattern matching in SQL as it's generally something better left to the surrounding programming language.

Hope that helps!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 05:15PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month