M
marc.gibian
I need to formulate a query that tests that a field is a member of a
list of acceptable values, but can't figure out the mechanics. Say we
have a table with a column containing an ID. I have a list of
interesting ids in my application, for which I'd like to write a query:
SELECT * FROM table where ID in (list of values)
where (list of values) is the array of interesting ids that my
application has already built. The simple solution of selecting the
interesting IDs within the query is not available as it takes some
significant business logic to build it. Is there some form of Array
parameter that I can use to bind the values I'm interested in into a
parameter in my SQL statement? I'd love something like:
SqlCommand cmd = connection.CreateCommand();
cmd.CommandText = "SELECT * FROM table WHERE ID in
(@ArrayParameter)";
cmd.Parameters.Add("@ArrayParameter", ????);
cmd.Parameters["@ArrayParamter"].Values = <ArrayList Variable>;
list of acceptable values, but can't figure out the mechanics. Say we
have a table with a column containing an ID. I have a list of
interesting ids in my application, for which I'd like to write a query:
SELECT * FROM table where ID in (list of values)
where (list of values) is the array of interesting ids that my
application has already built. The simple solution of selecting the
interesting IDs within the query is not available as it takes some
significant business logic to build it. Is there some form of Array
parameter that I can use to bind the values I'm interested in into a
parameter in my SQL statement? I'd love something like:
SqlCommand cmd = connection.CreateCommand();
cmd.CommandText = "SELECT * FROM table WHERE ID in
(@ArrayParameter)";
cmd.Parameters.Add("@ArrayParameter", ????);
cmd.Parameters["@ArrayParamter"].Values = <ArrayList Variable>;