Solved

Query Expression for contentents of a field except some values

Posted on 2014-03-26
4
213 Views
Last Modified: 2014-03-26
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
Comment
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
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 61

Accepted Solution

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

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

Open in new window


If you need to display 0 for those amounts:


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

Open in new window

0
 

Author Comment

by:Conernesto
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

by:Conernesto
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

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

The expression is:

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

Open in new window



You can assign it a column name like this:

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

Open in new window



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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question