Solved

Query Expression for contentents of a field except some values

Posted on 2014-03-26
211 Views
I have a table called Accounts. The table has two fields Accounts and Amounts. I am creating a query and need an expression that pulls amounts if the account is not account 1 or 5. Below is a sample of what I need. How do I write the expression?

Accounts      Amounts            Query Result wanted
1      100            0
2      200            200
3      300            300
4      400            400
5      500            0

conernesto
0
Question by:Conernesto
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

LVL 61

Accepted Solution

mbizup earned 500 total points
ID: 39956202
If you ONLY want those records:

``````SELECT  Account , Amount
FROM YourTable
WHERE Account <> 1 and Account <> 5
``````

If you need to display 0 for those amounts:

``````SELECT  Account , Amount, IIF(Account= 1 OR Account = 5, 0, Amount) AS NewAmount
FROM YourTable
``````
0

Author Comment

ID: 39956282
Accounts  Amounts    Expression Results wanted

1               100               0
2               200               200
3               300               300
4               400               400
5               500               0

The above is to clerify.
0

Author Comment

ID: 39956304
Can you provide the formula to enter the above in an expression since I will need to do more with this? For Example: Xpression: IIF([Account_tbl]![Account]?????.
0

LVL 61

Expert Comment

ID: 39956327
That's part of the SQL statement....

The expression is:

``````IIF(Account= 1 OR Account = 5, 0, Amount)
``````

You can assign it a column name like this:

``````NewAmount: IIF(Account= 1 OR Account = 5, 0, Amount)
``````

(You can toggle between SQL view and Design  view to see it written both ways)
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses
Course of the Month6 days, 7 hours left to enroll