Handling the exception

  • I have a calculated field in my SP. Please help to handle the exception rose if the start date and end date are same and occur a division by zero exception. How to return the value 1 if the start date and end date are same?

    SELECT Min(A.EndDate) AS EndDate,

    Sum(A.budgetedTotalWorkload)/ (DATEDIFF(day, A.StartDate, A.EndDate)) AS Workload

    INTO #TotalWorkload

    FROM #Activities2 AS A

    GROUP BY A.EndDate,A.StartDate

  • CASE wHEN (DATEDIFF(day, A.StartDate, A.EndDate)) = 0 THEN 1 ELSE Sum(A.budgetedTotalWorkload)/ (DATEDIFF(day, A.StartDate, A.EndDate)) END

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks Gila for that post.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply