title: How to case and if become sql command
body: <p>I have code that I want to become a SQL command.</p>
  
  <p>My table <code>leavetabletest</code> has these columns:</p>
  
  <pre><code>Holiday, IsRestDay, mNP1, mNP2, mNP3, mNP4, mNP5
  </code></pre>
  
  <p>First I need to group by and then do the case and if </p>
  
  <p>How to do it?</p>
  
  <pre><code>   Case Holiday='S'
          If IsRestDay
              mNP4_F8=mNP4_F8+Night_F8    
          Else
              mNP2_F8=mNP2_F8+Night_F8    
          Endif
  
     Case Holiday='L'
          IF IsRestDay
              mNP5_F8=mNP5_F8+Night_F8    
          Else
              mNP3_F8=mNP3_F8+Night_F8    
          Endif
  
     Other
          If IsRestDay
              mNP2_F8=mNP2_F8+Night_F8    
          Else
              mNP1_F8=mNP1_F8+Night_F8    
          Endif
  </code></pre>
  
  <p>I try to use case when, but it does not work</p>
  
  <pre><code>Select 
      sum(regular),
      case when holiday = 'S' and IsRestDay ='1' then sum(over_F8) end as    mOT6_F8
      case when holiday = 'S' and IsRestDay ='0' then sum(over_F8) end as mOT3_F8
      case when holiday = 'L' and IsRestDay ='1' then sum(over_F8) end as mOT5_F8
      case when  holiday = 'L' and IsRestDay ='0' then sum(over_F8) end as mOT4_F8
      case when holiday &lt;&gt; 'S' and holiday &lt;&gt; 'L' and IsRestDay ='1' then sum(over_F8) end as mOT2_F8
      case when holiday &lt;&gt; 'S' and holiday &lt;&gt; 'L' and IsRestDay ='0' then sum(over_F8) end as mOT1_F8
  From 
      leavetabletest
  group by 
      EmployeeID, DepartmentID, SectionID
  </code></pre>