Selasa, 10 Februari 2015

[MS_AccessPros] WHERE clause for variable number of values

 

I have a query that needs to list financial data from a table for items where a designated field, TypeId, matches a user selected value. Ther TypeId is a user selection from a dropdown of values,so the matched type id is checked against the table to restrict to that selected– standard stuff so far. There is a twist though, in the selection (this part is in Excel not Access), there is one choice that has no matching values in the table as it relates to 3 of the ids; for this selection I need to pull back those rows with any of those 3 values. I would like to know how to build a query in Access and call the query rather than build the SQL in Excel and just exec that.

 

In (very) pseudo-code, it would be something like

 

Paramters param.type.id Long;

 

SELECT some fields

FROM table1 AS t1

WHERE (IF param.type.id = 7 THEN t1.typeid IN (1, 2, 4) ELSE t1.typeid = param.type.id);

 

Clearly this doesn’t work, but I hope I have given enough to explain what I am trying to achieve.

 

In SQL Server stored procs I would probably just load a temp table and match against that, but that is not possible in an Access query.

 

Any ideas as to how I can achieve this, or another approach to get to the end-result?

 

__._,_.___

Posted by: "Bob Phillips" <bob.phillips@dsl.pipex.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (1)

.

__,_._,___

Tidak ada komentar:

Posting Komentar