Here is the query with the where the '=' has been replaced by 'IN':
- Code: Select all
Let ( [
// Define Carriage Return Substitution Character
ReturnSub = "\n" ;
// Enable the second line here if you want the header in your results
header = "";
//header = "b._id_table3";
// Define Table variables
aTABLE2 = Quote ( GetValue ( Substitute ( GetFieldName ( TABLE2::_id_table2 ) ; "::" ; ¶ ) ; 1 ) ) & " a" ;
bTABLE3 = Quote ( GetValue ( Substitute ( GetFieldName ( TABLE3::_id_table3 ) ; "::" ; ¶ ) ; 1 ) ) & " b" ;
// Define Field Variables
a_id_table2 = "a." & Quote ( GetValue ( Substitute ( GetFieldName ( TABLE2::_id_table2 ) ; "::" ; ¶ ) ; 2 ) ) ;
b_id_table3 = "b." & Quote ( GetValue ( Substitute ( GetFieldName ( TABLE3::_id_table3 ) ; "::" ; ¶ ) ; 2 ) ) ;
bid_table2 = "b." & Quote ( GetValue ( Substitute ( GetFieldName ( TABLE3::id_table2 ) ; "::" ; ¶ ) ; 2 ) ) ;
// Build SQL Query
q =
"SELECT DISTINCT " & b_id_table3 & "
FROM " & aTABLE2 & "
INNER JOIN " & bTABLE3 & " ON " & a_id_table2 & " = " & bid_table2 & "
WHERE " & a_id_table2 & " IN (?) " ;
// Run SQL Query
result = ExecuteSQL ( q ; Char ( 9 ) ; "|*|" ; $myVariableHere ) ] ;
// Clean up carriage returns
List ( header ; Substitute ( result ; [ ¶ ; ReturnSub ] ; [ "|*|" ; ¶ ] ) ) )
The problem is that the IN parameter seems to want me to specify the number of items in my list within the actual query. So for example, if I have a list with 3 items, the line with 'IN' would look like
- Code: Select all
WHERE " & a_id_table2 & " IN (?, ?, ?) " ;
If I have a list of items with 10 items, it functions correctly if I do this
- Code: Select all
WHERE " & a_id_table2 & " IN (?,?,?,?,?,?,?,?,?) " ;
How would I go about correctly formatting this query?