title: Sql Server Group by and Case When
body: <p>Suppose we have this table contents:</p>
  
  <pre><code>id  type  value
  1    A    X1122
  1    B    JJHJU
  2    A    POIUY
  2    C    YUHGF
  </code></pre>
  
  <p>and I want to get this solution by a select:</p>
  
  <pre><code>id  valueA  valueB  valueC
  1   X1122   JJHJU   NULL
  2   POIUY   NULL    YUHGF
  </code></pre>
  
  <p>My first attempt was this:</p>
  
  <pre><code>SELECT id, CASE type WHEN A THEN value ELSE NULL END AS valueA
  , CASE type WHEN B THEN value ELSE NULL END AS valueB
  , CASE type WHEN C THEN value ELSE NULL END AS valueC
  FROM table
  GROUP BY id
  </code></pre>
  
  <p>but it returns me the error </p>
  
  <blockquote>
    <p>The columns 'type' and 'value' needs to be in GROUP BY statement</p>
  </blockquote>
  
  <p>Any suggestion?</p>