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
Solved

Case Statement in Access Query

Posted on 2014-09-15
2
326 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
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

856 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