title: How to use case statement in a union
body: <p>Below is a part of my script. </p>
  
  <pre><code>select a. itemcode, sum(b.quantity) 'y1qty', 
      isnull(null,0) as 'yr2qty', sum(c.amt) 'yr1amt' 
      isnull(null,0) as 'yr2amt',
  from ABC a
  left join DEF b on a.itemcode = b.itemcode
  group by a. itemcode
  
  UNION
  
  select  a1. itemcode, isnull(null,0) as 'yr1qty',
      sum(b1.quantity) 'yr2qty', isnull(null,0) as 'yr1amt',
      sum(c.amt) 'yr2amt' 
  from ABC a1
  left join DEF b1 on a1.itemcode = b1.itemcode
  group by a1.itemcode
  </code></pre>
  
  <p>Table A: SAmple output (based on the query above)</p>
  
  <pre><code>itemcode     y1qty  yr2qty   yr1amt      yr2amt
  item 001     150      0       200.00       0
  item 002      0      300        0         150.00
  item 003      0      50         0         100.00
  item 004     20      0        150.00       0       
  </code></pre>
  
  <p>I want to insert a case statement wherein logic is something like this: 
  if y1qty = 0 and yr2qty = 0 then blah blah..
  if y1qty = 0 and y2qty > 0 then  blah blah..    'DIff'</p>
  
  <p>and aiming to achieve this result:</p>
  
  <pre><code>Table B: 
  itemcode     y1qty  yr2qty   Diff      yr1amt      yr2amt
  item 001     150      0         0        200.00       0
  item 002      0      300       100        0         150.00
  item 003      0      50        100        0         100.00
  item 004     20      0           0      150.00       0 
  item 005     20      30       1000      100.00      200.00
  </code></pre>