PDA

View Full Version : Solved: creating a string for the 'Where' portion of the query



mferrisi
07-09-2007, 01:50 PM
Hello,

I'm not too familiar with access, but I'm attempting run a query on access,

cmd.CommandText = "SELECT Returns.Date, Returns.Return " & _
"FROM HistReturns " & _
"WHERE j " & _
"ORDER BY Returns.Date;"

Now, I'm trying to make j a string that contains conditions found in a two-columned array. i.e. the array contains 200 rows cities and states, so I am trying to create a string (in this case, "j"), that holds the parameters, since I want to query for 200 specific values.

For example, I need j to be a string that does the same thing as if I inserted something like this in its place:

(Returns.City='Chicago') AND (Returns.State='IL') OR (Returns.City='Springfield') AND (Returns.State='MA') OR
(Returns.City='Springfield') AND (Returns.State='IL')

So, my question is:
When inserting the 'j' , what should the format look like?

ie WHERE 'j' ?
WHERE ' & j & '?

Please let me know if that is not clear.

Thank you

asingh
07-09-2007, 05:58 PM
try this WHERE ('" & j & "' = .....)

matthewspatrick
07-10-2007, 09:10 AM
mferrisi,

asingh is absolutely right on how to integrate the variable j into the
expression. Do you need help generating j, of do you have that covered?

mferrisi
07-10-2007, 09:20 AM
I was able to generate the string after a few trials, and was able to run the query successfully. Thank you for your help!