title: Changing 'IF and NULL' from MySQL to SQL Server
body: <p>I have problem in changing the query from MySQL to SQL Server. I tried to change it to <code>ISNULL</code> and <code>IIF</code> in SQL but still doesn't work. Any tips or help are welcome, thanks!</p>
  
  <p><strong>Question 1 :</strong> </p>
  
  <p><strong>MYSQL</strong></p>
  
  <pre><code>SELECT i.item_name
           , r.item_version
           , SUM(IF(r.group_status=1,r.quantity,0)) AS `Approved`
           , SUM(IF(r.group_status=2,r.quantity,0)) AS `NotApproved`
           , SUM(r.quantity)                        AS `Total`
        FROM requesters r
        JOIN items i
          ON i.item_id = r.item_id
       WHERE r.group_status IN (1,2)
         AND r.requested_date &gt;= '$a'
         AND r.requested_date &lt;= '$b'
       GROUP
          BY i.item_name
           , r.item_version
  </code></pre>
  
  <p><strong>SQL Server</strong></p>
  
  <pre><code>SELECT i.item_name
       , r.item_version
       , SUM(ISNULL(r.group_status=1,r.quantity,0)) AS `Approved`
       , SUM(ISNULL(r.group_status=2,r.quantity,0)) AS `NotApproved`
       , SUM(r.quantity)                        AS `Total`
    FROM requesters r
    JOIN items i
      ON i.item_id = r.item_id
   WHERE r.group_status IN (1,2)
     AND r.requested_date &gt;= '$a'
     AND r.requested_date &lt;= '$b'
   GROUP
      BY i.item_name
       , r.item_version
  </code></pre>
  
  <p>It keep saying <code>Incorrect syntax near ','</code> and still doesn't work.</p>
  
  <p><strong>Question 2 :</strong></p>
  
  <p><strong>MYSQL</strong></p>
  
  <pre><code>SELECT IFNULL(SUM(IF(endusers.price,endusers.price,0)),0) AS `totalprice` 
  FROM endusers
  WHERE requester_code = '$req_code'
  </code></pre>
  
  <p><strong>SQL Server</strong></p>
  
  <pre><code>SELECT NULLIF(SUM(COALESCE(endusers.price,endusers.price,0)),0) AS 'totalprice' 
  FROM endusers 
  WHERE requester_code = '$req_code'
  </code></pre>
  
  <p>The problem when I use <code>COALESCE</code> in Question 2, it won't display <code>'0'</code> when there's no value in the table.</p>