title: Getting error: Msg 8134, Level 16, State 1, Line 1
body: <p>I have reviewed the other replies to this problem, but cannot find the appropriate response to my situation.  I am trying to divide "actual hours" by "estimated hours".  However, estimated hours can be null (no entry) or zero.  Actual hours can be zero.  So when I get to the division statement, I can't have estimated hours as null or actual hours as zero.  My "coalesce" statements don't appear to be helping. Any advice would be helpful.</p>
  
  <pre><code>SELECT PUV.ProjectName, PUV.[Project ID], PUV.[Project Director], PUV.[Project Owner (Manager)], PUV.[Project Type1], **COALESCE( PUV.[Estimated Hours], 0 ) AS EstHours
  ,PUV.ProjectStatusDate, PUV.ProjectStartDate, PUV.ProjectBaseline0StartDate, PUV.ProjectActualStartDate, PUV.ProjectStartVariance, PUV.ProjectBaseline0FinishDate
  ,PUV.ProjectFinishDate, PUV.ProjectFinishVariance, PUV.ProjectActualFinishDate, PUV.ProjectWork, PUV.ProjectBaseline0Work, PUV.ProjectActualWork, PUV.ProjectWorkVariance, PUV.ProjectRemainingWork
  ,PUV.[Project Phase], PUV.[Hold - Canceled Indicator], CWI.StageName, TB.TB_BASE_NUM, MAX (TB.CREATED_DATE) RecentBaseline
  ,CASE WHEN PUV.[Estimated Hours] is null then 0 END AS [Estimated%]
  ,Case When PUV.ProjectActualWork &lt;&gt; 0 THEN cast(COALESCE(PUV.ProjectActualWork,0) as DECIMAL(20,2) )/Cast(COALESCE(PUV.[Estimated Hours],0)as decimal(20,2)) Else  0 End   AS  [Estimated%]* 
  --DATEDIFF(day, PUV.ProjectBaseline0FinishDate, PUV.ProjectFinishDate)
  FROM  MSP_EpmProject_UserView AS PUV
  LEFT OUTER JOIN (
      SELECT WSI.ProjectUID, WP.PhaseName, WP.PhaseUID, WS.StageName, WS.StageUID
      FROM  MSP_EpmWorkflowStage  AS WS              
      INNER JOIN MSP_EpmWorkflowPhase AS WP ON  WS.PhaseUID = WP.PhaseUID            
      INNER JOIN MSP_EpmWorkflowStatusInformation AS WSI ON WS.StageUID = WSI.StageUID AND WSI.StageEntryDate IS NOT NULL AND (WSI.StageStatus != 0 AND WSI.StageStatus != 4)
      ) AS CWI ON PUV.ProjectUID = CWI.ProjectUID
  JOIN sps_ppm_IT_Published.dbo.MSP_TASK_BASELINES AS TB ON PUV.ProjectUID = TB.PROJ_UID
  WHERE TB.TB_BASE_NUM = 0
  GROUP BY PUV.ProjectName, PUV.[Project ID], PUV.[Project Director], PUV.[Project Owner (Manager)], PUV.[Project Type1], PUV.[Estimated Hours]
  ,PUV.ProjectStatusDate, PUV.ProjectStartDate, PUV.ProjectBaseline0StartDate, PUV.ProjectActualStartDate, PUV.ProjectStartVariance, PUV.ProjectBaseline0FinishDate
  ,PUV.ProjectFinishDate, PUV.ProjectFinishVariance, PUV.ProjectActualFinishDate, PUV.ProjectWork, PUV.ProjectBaseline0Work, PUV.ProjectActualWork, PUV.ProjectWorkVariance, PUV.ProjectRemainingWork
  ,PUV.[Project Phase], PUV.[Hold - Canceled Indicator], CWI.StageName, TB.TB_BASE_NUM
  ORDER BY PUV.ProjectName
  </code></pre>