Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct CASE SELECT Statement in Access 2010? [duplicate]

I am using vb.net and Access 2010 as the database (.accdb)

This works with MySQL:

SELECT user_id, username, first_name, middle_name, last_name,
CASE is_enable WHEN 1 THEN 'Yes' ELSE 'No' END 
FROM tbl_user_accounts ORDER BY user_id

But when passed the same query to Access, I get the following error:

Unrecognized keyword WHEN.

So I assume that the CASE Statement is different in access, or does access has that function at all?

P.S.
is_enable is boolean

like image 674
Ruben_PH Avatar asked Feb 09 '13 06:02

Ruben_PH


People also ask

Can you duplicate a query in Access?

You can also copy a query from one Access database to another. Open the "target" database in Access. Start a new "instance" of Access by clicking the Access icon on the Windows Start menu or from a shortcut. Select the query in the Navigation Pane in the first database and drag it to the other Access window.

What is duplicate query?

A find duplicates query allows you to search for and identify duplicate records within a table or tables. A duplicate record is a record that refers to the same thing or person as another record.

Why is my Access query returning duplicates?

If a field with a one-to-many relationship is in your filters, output, or sort, the record will appear multiple times-- once for each time the record meets the criteria. This allows you to check your query to ensure you get the expected results.


2 Answers

Figured it out:
Access 2010 does not have the CASE function, we use SWITCH instead.

SELECT user_id, username, first_name, middle_name, last_name, SWITCH(is_enable=True,'Yes',is_enable=False,'No') FROM tbl_user_accounts ORDER BY user_id

Thanks to chuff and JW.

like image 145
Ruben_PH Avatar answered Sep 28 '22 04:09

Ruben_PH


Alternatively, you can use IIF

IIF(is_enable = 1 , 'YES', 'NO')
like image 27
John Woo Avatar answered Sep 28 '22 05:09

John Woo