?
Solved

Case Statement in Access Query

Posted on 2014-09-15
2
Medium Priority
?
335 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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 custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

752 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