Click to See Complete Forum and Search --> : Accessing a list in SQL


bradleybebad
06-12-2009, 12:20 PM
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?

dingbat
06-12-2009, 12:51 PM
Try the find_in_set() (http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set) function. If it returns >0, then it's in the list.

bradleybebad
06-12-2009, 01:20 PM
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.

dingbat
06-12-2009, 02:23 PM
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)

bradleybebad
06-12-2009, 02:53 PM
anyone have any clue on how to do this in MSSQL?

b4web
06-16-2009, 12:20 PM
Is there a "IN" in MSSQL? For example:

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