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 multiple fields

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2007-02-06 : 12:51:33
Trying to build a search engine and I need to search 3 fields in one table. Like if someone types in "I am a big fan of the colts". Can someone point me in the right direction how to do a search for the words in the 3 fields?

Dave

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-02-06 : 13:58:18
SELECT ...
FROM YourTable
WHERE Column1 = 'I am a big fan of the colts.' OR
Column2 = 'I am a big fan of the colts.' OR
Column3 = 'I am a big fan of the colts.'

You can also use LIKE if you are looking for that text somewhere in the column.

Oh and I love the Chargers!!! We'll be back!

Tara Kizer
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-02-06 : 14:06:27
To easy Mrs. Kizer

I'm sure they want to parse the words out, search for any of them, in three different columns

Riiiiiiight?

I'm thinking, parse, insert to temp table, join to three tables



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-06 : 14:09:53
SELECT distinct c.*
FROM YourTable as c
cross apply dbo.fnSplit('I am a big fan of the colts.', ' ') as x
WHERE c.Column1 = x.part or c.Column2 = x.part OR c.Column3 = x.part


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-02-06 : 14:12:53
cross apply?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2007-02-07 : 07:06:25
What about using FREETEXT or CONTAINS


quote:
Originally posted by X002548

cross apply?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam





Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-02-07 : 09:07:09
quote:
Originally posted by helixpoint

What about using FREETEXT or CONTAINS


quote:
Originally posted by X002548

cross apply?


I would imagne CONTAINS mean the entire string...want to shed some light on what you want to do?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam









Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -