Solved

Access Iif  to MySQL Case?

Posted on 2008-10-13
4
840 Views
Last Modified: 2012-05-05
I have a simple query that totals weekday vs. weekend sales in MS Access that I need to translate to MySQL.

In Access it is:

SELECT
daily_store_sales.account_code,
Sum(IIf(DatePart("w",[store_report_date]) IN (2,3,4,5,6),qty_daily_sales,0)) AS WDTotal,
Sum(IIf(DatePart("w",[store_report_date]) In (1,7),qty_daily_sales,0)) AS WETotal,
Sum(qty_daily_sales)
FROM
daily_store_sales
GROUP BY
daily_store_sales.account_code

My MySQL translation (of many variations) is not working:

SELECT
daily_store_sales.account_code,
Sum(CASE WHEN DAYOFWEEK([store_report_date]) IN (2,3,4,5,6) THEN SELECT qty_daily_sales ELSE SELECT 0)) AS WDTotal
FROM
daily_store_sales
GROUP BY
daily_store_sales.account_code

Can CASE be used in SELECTs like this?  And if not, what is a better way to handle if/then logic in MySQL queries?

Many Thanks.  
0
Comment
Question by:bishopkd
[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
  • 2
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22706476
yes, but no the SELECT inside the CASE..
Sum(CASE WHEN DAYOFWEEK([store_report_date]) IN (2,3,4,5,6) THEN qty_daily_sales ELSE 0 END)) AS WDTotal

Open in new window

0
 

Author Comment

by:bishopkd
ID: 22710669
Thanks, but this is still giving me a syntax error for this line.  Any other thoughts?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 22710775
sorry. the [] in ms access are `` in mysql:
Sum(CASE WHEN DAYOFWEEK(`store_report_date`) IN (2,3,4,5,6) THEN qty_daily_sales ELSE 0 END)) AS WDTotal

Open in new window

0
 

Author Comment

by:bishopkd
ID: 22710798
You are a prince among men.  Thank you!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

636 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