I have inherited some code with a divide by zero error.
I keep getting the error and not sure if it is the code or where I am placing it. Should this line be added or replace a line?
Tried adding and replacing with this case statement: CASE WHEN SUM(PREOP_MME) = 0 THEN 0 ELSE SUM(PREOP_MME) / SUM(COUNT_CASES) END AS PREOP_MME).
SELECT
PROCEDURE_NM
,SUM(PreOp_MME) / SUM(COUNT_CASES) PreOp_MME
,SUM(IntraOp_MME) / SUM(COUNT_CASES) IntraOp_MME
,SUM(PostOp_MME / PostOp_LOS) PostOp_MME
,SUM(Discharge_MME) / SUM(COUNT_CASES) Discharge_MME
,SUM(TOTAL_OVERALL_MME) / SUM(COUNT_CASES) Overall_MME
FROM (
SELECT DISTINCT
Spine.LOG_ID
,Spine.SERV_AREA_ID [Service Area ID]
,Spine.LOC_ID [Revenue Location ID]
,Spine.PRIMARY_PHYS_ID [Provider ID]
,Spine.SURGERY_DATE
,Spine.COUNT_CASES
,Spine.PROCEDURE_NM
,Spine.PostOp_LOS
,(PreOp.SUM_SIG * PreOp.PreOp_MME) AS PreOp_MME
,(IntraOp.SUM_SIG * IntraOp.IntraOp_MME) AS IntraOp_MME
,(PostOp.SUM_SIG * PostOp.PACU_MME) AS PostOp_MME
,DischMeds.DOSE_MME AS Discharge_MME
,(PreOp.SUM_SIG * PreOp.PreOp_MME) +
(IntraOp.SUM_SIG * IntraOp.IntraOp_MME) +
(PostOp.SUM_SIG * PostOp.PACU_MME) + DischMeds.DOSE_MME as TOTAL_OVERALL
A = 0thenA / anythingis also 0 and you wont need a case - Juan Carlos OropezaA / 0doesnt give error, just return null. - Juan Carlos Oropeza[Service Area ID]say MSSQL. MySql should looks like`Service Area ID`- Juan Carlos Oropeza