title: Date in SQL Pivot to be transformed from yyyy-mm-dd to mm-yy
body: <p>I have a pivot query IN SQL Server 2016 that works somewhat good:</p>
  
  <pre><code>select *
  
  FROM (select Analyst,Task_Type,Load,Completed,Date_Of_Assignment
  
   from mytable where Task_Type IN ('Loans') ) as TEST PIVOT 
  
  (
  
  SUM(Completed)
  
  FOR 
  
  [Date_Of_Assignment] IN ([2018-05-22],[2018-06-22],[2018-07-22])
  
  ) as P
  </code></pre>
  
  <p>it returns as:</p>
  
  <pre><code>Agent_Name  Task_Type   Total_Received  2018-05-22  2018-06-22 2018-07-22
  Steve       Loans        20                 15         15           15
  Cathe       Loans        20                 15         15           15
  Adam        Loans        20                 15         15           15
  Klaus       Loans        20                 15         15           15
  </code></pre>
  
  <p>which is cool, but I need it more like this</p>
  
  <pre><code>Agent_Name  Task_Type   Total_Received    May 18     June 18      July 18
  Steve       Loans        20                 15         15           15
  Cathe       Loans        20                 15         15           15
  Adam        Loans        20                 15         15           15
  Klaus       Loans        20                 15         15           15
  </code></pre>
  
  <p>Considering that it might be more than one day of data per Load, actually it should be every workday.</p>
  
  <p>I tried by grouping by Date_ but it returns errors.</p>
  
  <p>If I do like:</p>
  
  <pre><code>select *
  
  FROM (select Analyst,Task_Type,Load,Completed,Date_Of_Assigment
  
  CASE WHEN FORMAT(Date_Of_Assigment,'MM-yy') = '05-18' THEN 'May 18'
       WHEN FORMAT(Date_Of_Assigment,'MM-yy') = '06-18' THEN 'Jun 18'
       WHEN FORMAT(Date_Of_Assigment,'MM-yy') = '07-18' THEN 'Jul 18'
  END AS MonthT
  
   from mytable where Task_Type IN ('Loans') as TEST PIVOT 
  
  
  (
  
  SUM(Completed)
  
  FOR 
  
  [MonthT] IN (['May 18'],['Jun 18'],['Jul 18'])
  
  ) as P
  </code></pre>
  
  <p>I receive:</p>
  
  <pre><code>Analyst    Task     Total_Received   'May 18'   'Jun 18'    'Jul 18'
  Steve     Billing     20                NULL       NULL       NULL
  Cathe     Billing     20                NULL       NULL       NULL
  Adam      Billing     20                NULL       NULL       NULL
  Klaus     Billing     20                NULL       NULL       NULL
  </code></pre>
  
  <p>It does turn Dates into columns but with NULLS only.</p>
  
  <p>Data types are: Date for Date_Of_Assigment, nvarchar for Task_Type and Analyst and integer for the rest of columns.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Thank you very much</p>