Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Search multiple words in SQL

Participant ,
May 27, 2009 May 27, 2009

I want to be able to search on multiple words in sql.  If someone inputs into the search field multiple words like 'biofuels corn industry' . I want to return all records that has any of those words in them.  Below is my code:(which only brings back the phrase and not individual words from the database)

and (
            path like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#arguments.searchterms#%">   
            or
            body like <cfqueryparam cfsqltype="cf_sql_longvarchar" value="%#arguments.searchterms#%">   
            or
            summary like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#arguments.searchterms#%">
            or
            author like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#arguments.searchterms#%">
        )

897
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 27, 2009 May 27, 2009

something like this:

select somefields

from sometables

where 1 = 1

and

(

<cfloop list = "biofuels corn industry" index = "word" delimiters = " ">

or concat(field1, field2, etc) like '%#word##%'

</cfloop>

or 1 = 2

)

Just so you know, this will be slow.   Also, if any of those fields allow nulls, you'll have to deal with that.

Translate
LEGEND ,
May 27, 2009 May 27, 2009

something like this:

select somefields

from sometables

where 1 = 1

and

(

<cfloop list = "biofuels corn industry" index = "word" delimiters = " ">

or concat(field1, field2, etc) like '%#word##%'

</cfloop>

or 1 = 2

)

Just so you know, this will be slow.   Also, if any of those fields allow nulls, you'll have to deal with that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 27, 2009 May 27, 2009
LATEST

Thanks, that did it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources