Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching lots of fields

Status
Not open for further replies.

emozley

Technical User
Jan 14, 2003
769
GB
Hi,

I have table that has about twenty fields that I would like to search. Rather than executing a query that says:

SELECT FROM MyTable WHERE FieldA LIKE '%searchtext%' OR FieldB LIKE '%searchtext%' OR FieldC LIKE '%searchtext%' OR FieldD LIKE '%searchtext%' OR FieldE LIKE '%searchtext%' OR FieldB LIKE '%searchtext%' etc..etc...etc..

I was wondering if there is a query that says select everything in row from table where anything in row is like '%searchstring%'. Searching 20 fields with just one search term will be bad enough but if the user enters two, three or even four words into the search box the query will become massive.

Thanks very much

Ed
 

You could simply concatonate the fields into one long string then search that

So

Select * from Table where F1 + F2 + F3 like '%Term%'




I love deadlines. I like the whooshing sound they make as they fly by
Douglas Adams
(1952-2001)
 
Have you tried the following:
Code:
SELECT * 
FROM MyTable
WHERE @SearchText IN (Field1, Field2, Field3);

--------------------------------------------------
Stubbornness is a virtue -- if you are right. --Chuck Noll
--------------------------------------------------
 
You could simply concatonate the fields into one long string then search that

So

Select * from Table where F1 + F2 + F3 like '%Term%'
[/code]

Not so great if there's a NULL in F1.

soi là, soi carré
 
Agreed

Should have gone with

isnull(field1,'')+isnull(filed2,'') etc etc



I love deadlines. I like the whooshing sound they make as they fly by
Douglas Adams
(1952-2001)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top