title: SQL - Group By Into Separate Columns
body: <p>Using SQL Server 2008 R2. I'm not sure if this is possible, but I would like to group by two columns and take their differences and place them into new columns. It's probably easier to explain with an example:</p>
  
  <pre>
  BEFORE::
  
  [DATE]      [ID]                                  [AMT] [TYPE]
  2013-01-11  36374DCD-47FE-48D8-8E70-8D3B37385311    2   20
  2013-01-11  36374DCD-47FE-48D8-8E70-8D3B37385311    10  21
  2013-01-11  4434E2D5-1D08-45FA-AADF-F653BF9A0D97    4   20
  2013-01-11  4434E2D5-1D08-45FA-AADF-F653BF9A0D97    4   21
  
  AFTER::
  
  [DATE]      [ID]                                 [AMT 20] [AMT 21]
  2013-01-11  36374DCD-47FE-48D8-8E70-8D3B37385311    2       10
  2013-01-11  4434E2D5-1D08-45FA-AADF-F653BF9A0D97    4       4
  
  
  </pre>
  
  <p>This is the SQL I have so far:</p>
  
  <pre><code>SELECT 
      CAST(TransDate AS DATE) AS [TransDate],ItemID,COUNT(TransactionTypeID) AS [TransAmt], TransactionTypeID
  FROM 
      Transactions
  WHERE 
      TransDate BETWEEN '2013-01-01 10:00:00' AND '2013-02-01 10:00:00'
      AND TransactionTypeID IN (20,21)
  GROUP BY
      CAST(TransDate AS DATE),ItemID,TransactionTypeID
  </code></pre>
  
  <p>Any help is appreciated, thanks!</p>