trouble using the CONTAINS() function in sql server

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

    trouble using the CONTAINS() function in sql server

    I am having trouble using the CONTAINS function in sql
    server(enterpri se manager). I am typing the following:

    Select *
    FROM mytable
    WHERE CONTAINS(myfiel d,'mystring')

    This returns the error:

    Query Designer encountered a MS Design Tools error:
    ODBC error:[Microsoft][ODBC SQL Server Driver]'CONTAINS' is not a
    recognized
    function name.[Microsoft][ODBC SQL Server Driver][SQL
    Server]Statement(s) could
    not be prepared.

    According to the T-SQL reference on msdn this is a supported function?
    Am I typing something incorrectly? If this is not supported, is
    there an equivalent to this function? In my field I have some comma
    delimited values ie 'apple,orange'. So I need to be able to discern
    which records contain orange. The LIKE keyword doesn't seem to work
    for this scenario. Any help would be greatly appreciated.
  • Dave Hau

    #2
    Re: trouble using the CONTAINS() function in sql server

    Works for me. Just add it directly to the SQL statement, unless you're
    using an older SQL Server version than 2000?

    Another way to do this is to use LIKE, as you mentioned:

    select * from mytable where myfield like '%orange%'

    HTH,
    Dave


    "Jason" <jfreets2@yahoo .com> wrote in message
    news:ec1eda50.0 311211559.1318c 619@posting.goo gle.com...[color=blue]
    > I am having trouble using the CONTAINS function in sql
    > server(enterpri se manager). I am typing the following:
    >
    > Select *
    > FROM mytable
    > WHERE CONTAINS(myfiel d,'mystring')
    >
    > This returns the error:
    >
    > Query Designer encountered a MS Design Tools error:
    > ODBC error:[Microsoft][ODBC SQL Server Driver]'CONTAINS' is not a
    > recognized
    > function name.[Microsoft][ODBC SQL Server Driver][SQL
    > Server]Statement(s) could
    > not be prepared.
    >
    > According to the T-SQL reference on msdn this is a supported function?
    > Am I typing something incorrectly? If this is not supported, is
    > there an equivalent to this function? In my field I have some comma
    > delimited values ie 'apple,orange'. So I need to be able to discern
    > which records contain orange. The LIKE keyword doesn't seem to work
    > for this scenario. Any help would be greatly appreciated.[/color]


    Comment

    • Scott Shuster

      #3
      Re: trouble using the CONTAINS() function in sql server

      I've never used contains.... Have you tried CharIndex?

      Ex:
      Select *
      FROM tablename
      where charindex('stri ngtofind',colum n) > 0



      Scott




      jfreets2@yahoo. com (Jason) wrote in message news:<ec1eda50. 0311211559.1318 c619@posting.go ogle.com>...[color=blue]
      > I am having trouble using the CONTAINS function in sql
      > server(enterpri se manager). I am typing the following:
      >
      > Select *
      > FROM mytable
      > WHERE CONTAINS(myfiel d,'mystring')
      >
      > This returns the error:
      >
      > Query Designer encountered a MS Design Tools error:
      > ODBC error:[Microsoft][ODBC SQL Server Driver]'CONTAINS' is not a
      > recognized
      > function name.[Microsoft][ODBC SQL Server Driver][SQL
      > Server]Statement(s) could
      > not be prepared.
      >
      > According to the T-SQL reference on msdn this is a supported function?
      > Am I typing something incorrectly? If this is not supported, is
      > there an equivalent to this function? In my field I have some comma
      > delimited values ie 'apple,orange'. So I need to be able to discern
      > which records contain orange. The LIKE keyword doesn't seem to work
      > for this scenario. Any help would be greatly appreciated.[/color]

      Comment

      • Bill

        #4
        Re: trouble using the CONTAINS() function in sql server

        Great thanks for your help. After posting this question I read on msdn
        that some keywords are new for sql server 2000. The "contains" function
        is on that list. I tried LIKE "%mystring% " and it works fine!!


        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        Working...