database search

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • huzz

    database search

    I've a table filed holds keywords seperated by comma, and a web search form
    where a user can type one of multiple keywords in the search text field
    seperated by comma aswell. How do i create a sql statement to bring results
    that matches one or more keywords in the database?

    Many thanks in advance..

    huzz


  • Dave

    #2
    Re: database search

    More of a database question than a .NET question. You may be able to find your answer by posting in a more appropritate group.

    Assuming your using SQL Server, check out the IN keyword in T-SQL and the LIKE keyword.

    IN lets you group fields together using commas.
    LIKE lets you perform wildcard comparisons between strings.

    Examples:

    SELECT * FROM MyTable WHERE @Search IN (NameField, DescriptionFiel d)
    SELECT * FROM MyTable WHERE NameField LIKE @Search + '%'

    If your going to search a comma-seperated list of values stored in a single field, you may have to use Dynamic-SQL. There are
    examples of how to use this in the SQL Server docs and on the web.

    Check out the stored procedure named, ""

    --
    Dave Sexton
    dave@www..jwaon line..com
    -----------------------------------------------------------------------
    "huzz" <huzz@discussio ns.microsoft.co m> wrote in message news:57BF3087-4B14-46B5-9A52-CC9C6ED11CE4@mi crosoft.com...[color=blue]
    > I've a table filed holds keywords seperated by comma, and a web search form
    > where a user can type one of multiple keywords in the search text field
    > seperated by comma aswell. How do i create a sql statement to bring results
    > that matches one or more keywords in the database?
    >
    > Many thanks in advance..
    >
    > huzz
    >
    >[/color]


    Comment

    • Cowboy \(Gregory A. Beamer\)

      #3
      Re: database search

      If you are storing in a garbage dump (table with lots of text,
      non-separated), your best option is using a full text index to index the
      comma separated keywords. Personally, I would consider a less taxing
      database structure, like one that enumerates the keywords, but that is just
      my feeling on this type of data. It may not be feasible in your situation.

      Regardless of your choice, the user's list of keywords presents you with
      options:

      1. Write the SQL in your app and submit to the database
      2. Turn the keyword list into XML and use the XML capabilities of the
      database (both Oracle and SQL Server can use this option)
      3. Create a stored procedure that puts the user list in a temp table and
      join that table with the tables being queried

      --
      Gregory A. Beamer
      MVP; MCP: +I, SE, SD, DBA

      *************** *************** *************** **
      Think outside the box!
      *************** *************** *************** **
      "huzz" <huzz@discussio ns.microsoft.co m> wrote in message
      news:57BF3087-4B14-46B5-9A52-CC9C6ED11CE4@mi crosoft.com...[color=blue]
      > I've a table filed holds keywords seperated by comma, and a web search
      > form
      > where a user can type one of multiple keywords in the search text field
      > seperated by comma aswell. How do i create a sql statement to bring
      > results
      > that matches one or more keywords in the database?
      >
      > Many thanks in advance..
      >
      > huzz
      >
      >[/color]


      Comment

      • Dave

        #4
        Re: database search

        Sorry, I submitted the post prematurely :)

        Check out the stored proc named, "sp_executesql" . There is a performance cost when using this approach.

        Also check out the FullText search capabilities for an alternative method of searching for keywords in Sql Server.

        I recommend just bringing down the data to your code, and checking the keywords there, if possible.


        Good Luck

        --
        Dave Sexton
        dave@www..jwaon line..com
        -----------------------------------------------------------------------
        "huzz" <huzz@discussio ns.microsoft.co m> wrote in message news:57BF3087-4B14-46B5-9A52-CC9C6ED11CE4@mi crosoft.com...[color=blue]
        > I've a table filed holds keywords seperated by comma, and a web search form
        > where a user can type one of multiple keywords in the search text field
        > seperated by comma aswell. How do i create a sql statement to bring results
        > that matches one or more keywords in the database?
        >
        > Many thanks in advance..
        >
        > huzz
        >
        >[/color]


        Comment

        Working...