Solved

Case Statement in Access Query

Posted on 2014-09-15
2
329 Views
Last Modified: 2014-09-15
Experts,

I would like to create a column in an SQL query in Acces.  I would usually do it with a Case Statement.

How would I do this.

If column_a = '777777' then column_b = 'CAT' else column_b = 'DOG'
0
Comment
Question by:morinia
[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 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40323372
column_b: iif(column_a="77777", "CAT","DOG")

(Note that it is IIF, not IF).
0
 
LVL 10

Expert Comment

by:Luke Chung
ID: 40323416
SELECT CASE statements can't be used in queries. IIF works for simple comparisons but as there are more options, it gets more and more difficult to understand and maintain over time.

Rather than a SELECT CASE statement, you may be better off using a table with the value pairs then link to it. That'll be easier to manage as it'll be in data rather than code.

Alternatively, if you want to use the SELECT CASE statement, Access lets you call your own Functions in queries. This powerful feature lets you combine the power of queries and VBA. See the section of my white paper on Using Custom Functions in Microsoft Access Queries for more details.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

687 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