locked
How to use case when function with SUM function ? RRS feed

  • Question

  • Dear All,

    May i know how to use case when function with SUM function ? kindly advise , thank you

    Example 

     Case When CONVERT(VARCHAR(8),LEAVE.START_DAY,112) > CONVERT(VARCHAR(8),DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0),112) then SUM(LEAVE.SUM_DAYS)AS TOTALDAYS else 0 END 

    Tuesday, October 22, 2013 2:33 AM

Answers

  • Try this.

    Sum(Case When CONVERT(VARCHAR(8),LEAVE.START_DAY,112) > CONVERT(VARCHAR(8),DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0),112) 
    then LEAVE.SUM_DAYS
    else 0 END) AS TOTALDAYS


    Vinay Valeti| If you think my suggestion is useful, please rate it as helpful. If it has helped you to resolve the problem, please Mark it as Answer

    • Proposed as answer by Sanjeewan Kumar Tuesday, October 22, 2013 2:52 AM
    • Marked as answer by Caulson Tuesday, October 22, 2013 5:06 AM
    Tuesday, October 22, 2013 2:39 AM