Selasa, 10 Februari 2015

Re: [MS_AccessPros] WHERE clause for variable number of values

 

Bob-


Try this:

SELECT some fields 
FROM table1 AS t1
WHERE IIf([Forms]![MyForm]![TypeID] = 7, [t1].[typeid] IN (1, 2, 4), [t1].[typeid] = [Forms]![MyForm]![TypeID])

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)




On Feb 10, 2015, at 9:06 AM, 'Bob Phillips' bob.phillips@dsl.pipex.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

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: John Viescas <johnv@msn.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)

.

__,_._,___

Tidak ada komentar:

Posting Komentar