www.webdeveloper.com
Results 1 to 6 of 6

Thread: Accessing a list in SQL

  1. #1
    Join Date
    Jun 2008
    Posts
    270

    Accessing a list in SQL

    I have a list of certain data (basically a number) that is separated by commas.
    If I wanted to make conditions in my query to the database, what is the best way?


    code:

    SELECT *
    FROM attributes
    WHERE attribute_values = #form.searchsize#

    The #form.searchsize# (if your curious to what kind of variable, it is coldfusion) is a variable passed on through a form. I basically need the field attribute_values to be searched in a each record. Each attribute_values contains several size numbers. IE - 1,2,3,4,5,.... How would I be able to question the database if #form.searchsize# is one of these numbers in the list?

  2. #2
    Join Date
    Mar 2009
    Posts
    36
    Try the find_in_set() function. If it returns >0, then it's in the list.

  3. #3
    Join Date
    Jun 2008
    Posts
    270
    SELECT attribute_values
    FROM attributes
    WHERE FIND_IN_SET('#form.searchsize#',attribute_values)


    Something like this?

    I tried this and could not get it to work.

    Basically I need to know if the #form.searchsize# variable is within the data (separated by commas, therefore commas are the delimiter) in each table within the attribute_values field.

    attribute_values (MS Access Field)

    1,2,3,4,5
    1,2,3,4,5,6,7
    2,3,4,5,6,7
    5,6,7,8,9

    I need to check each row's attribute values and see if my #form.searchsize# variable is in it's list.
    Last edited by bradleybebad; 06-12-2009 at 01:46 PM.

  4. #4
    Join Date
    Mar 2009
    Posts
    36
    Sorry, I guess find_in_set is just a mysql thing. I don't know Access, but I'd assume there's some sort of string search function.
    Maybe using IN would work:

    WHERE #form.searchsize# IN (attribute_values)

  5. #5
    Join Date
    Jun 2008
    Posts
    270
    anyone have any clue on how to do this in MSSQL?

  6. #6
    Join Date
    Jan 2009
    Posts
    14
    Is there a "IN" in MSSQL? For example:

    Select ..... Where attribute_values IN #form.searchsize#

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles