IF Then statement in MS Access Passthrough SQL Query

G

Guest

I am getting a "Division by zero error" in my pass-through query.

Here is my Select statement

SELECT
CD_CODE,(SUM(HP_SYSTEM_EXPECTED_BOOKINGS)/SUM(TOTAL_NET_BOOKINGS))*100 AS
SYSTEMSHARE

The error is because of a zero sum of Total_Net_Bookings.

How can I put a IF statement here to say if Sum(Total_Net_Bookings) = 0,
then SystemShare = 0 else ......

Any ideas?
 
G

Guest

If you work with MSSql then you need to use the case statement
CASE SUM(TOTAL_NET_BOOKINGS)
WHEN NULL THEN 0
ELSE
SUM(HP_SYSTEM_EXPECTED_BOOKINGS)/SUM(TOTAL_NET_BOOKINGS)*100
END AS SYSTEMSHARE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top