title: SQL table transformation - columns stat
body: <p>Let's imagine view: </p>
  
  <p><a href="https://i.stack.imgur.com/R9o5t.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R9o5t.jpg" alt="enter image description here"></a></p>
  
  <p>and I would like to transform it in elegant way, to something like the following:</p>
  
  <p><a href="https://i.stack.imgur.com/QfMCj.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QfMCj.jpg" alt="enter image description here"></a></p>
  
  <p>I am doing it with use following query:</p>
  
  <pre><code>SELECT empid,
      sum(CASE WHEN YEAR(ordermonth) = '2014' THEN val END) '2014',
      sum(CASE WHEN YEAR(ordermonth) = '2015' THEN val END) '2015',
      sum(CASE WHEN YEAR(ordermonth) = '2016' THEN val END) '2016'
  FROM Sales.EmpOrders
  GROUP BY empid;
  </code></pre>
  
  <p>Question is: what smart mechanism can I use to avoid listing cases manually, if there are many of them?</p>