Solved

Query Expression for contentents of a field except some values

Posted on 2014-03-26
4
199 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now