boolean search string to SQL

Results 1 to 3 of 3

Thread: boolean search string to SQL

  1. #1
    Join Date
    Dec 1969
    Posts
    21

    Default boolean search string to SQL

    Does anyone know of a method of converting a boolean search string (like the ones used in search engine advanced searches) into the WHERE clause of a standard SQL query?<BR>e.g. (word1 AND "word 2") OR "word 3" NOT word4<BR><BR>I&#039ve been trying to unscramble this one for 2 days now and my brain is completely swiss-cheesed. If anyone can sort it out, many thanks and I&#039ll support your MENSA application.<BR><BR>Cheers, Ric

  2. #2
    Nathan Pond Guest

    Default RE: boolean search string to SQL

    Ex. 1:<BR>Select * From Table Where textfield like &#039%word1%&#039 And textfield like &#039%word2%&#039<BR><BR>Ex. 2:<BR>Select * From Table Where textfield like &#039%word3%&#039 And textfield not like &#039%word4%&#039<BR><BR>hope this helps<BR><BR>Nathan

  3. #3
    Join Date
    Dec 1969
    Posts
    21

    Default RE: boolean search string to SQL

    Thanks Nathan, but what I really need is an algorithm or code to AUTOMATICALLY convert the boolean search string into the SQL WHERE clause. My problem is in unscrambling the logic behind the boolean algebra and producing the similar SQL statement.<BR><BR>For my previous example<BR>(word1 AND "word 2") OR "word 3" NOT word4<BR><BR>this would have to recognise () and "" and the keywords AND, OR and NOT to produce<BR><BR>SELECT DISTINCT * FROM sometable WHERE (somefield=&#039word1&#039 AND somefield=&#039word 2&#039) OR somefield=&#039word 3&#039 AND NOT somefield=&#039word4&#039<BR><BR>I&#039m only trying exact matches just now as using the LIKE operator slows down the query by quite a lot. I might use it later on for more unrestricted searches.<BR><BR>Cheers, Ric

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •