jasonwood Posted November 16, 2012 Posted November 16, 2012 How does one write a SELECT statement to find records with id that match any one id listed in a multi-key field? The following does not work because the contents of the multikeyfield will not entirely equal any individual record id. ExecuteSQL ( "SELECT field FROM table WHERE id=?" ; "" ; "¶" ; multikeyfield )
Ocean West Posted November 16, 2012 Posted November 16, 2012 http://fmforums.com/forum/topic/86755-sql-select-with-where-clause-uses-a-checkbox-field/
beverly Posted November 16, 2012 Posted November 16, 2012 The multi-key is return delimited. If they are all NUMBERS in the id field, you might try to change the returns to comma and use the IN comparison: ExecuteSQL ( " SELECT field FROM table WHERE id IN (?) " ; "" ; "¶" ; Substitute(multikeyfield;"¶";',' ) That should make it IN (1,2,3,4,5) Try it and see.
jasonwood Posted November 17, 2012 Author Posted November 17, 2012 That makes perfect sense to me, but I can't get it to work. I even tried hardcoding it like this in the data viewer: This works (but there's only one value): ExecuteSQL ( " SELECT ancestorsList FROM products_CATEGORIES WHERE id IN (?) " ; "" ; "¶" ; "10036" ) But with any of the following, nothing is returned. ExecuteSQL ( " SELECT ancestorsList FROM products_CATEGORIES WHERE id IN (?) " ; "" ; "¶" ; "10036,10039" ) with a space after comma: ExecuteSQL ( " SELECT ancestorsList FROM products_CATEGORIES WHERE id IN (?) " ; "" ; "¶" ; "10036,10039" ) with single quotes around each value: ExecuteSQL ( " SELECT ancestorsList FROM products_CATEGORIES WHERE id IN (?) " ; "" ; "¶" ; "'10036','10039'" )
Recommended Posts
This topic is 4450 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now