Solved

Access Iif  to MySQL Case?

Posted on 2008-10-13
4
836 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

734 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