title: How can I pivot data based on Month and year wise client Report
body: <p>I'm trying to retrieve data based on Month of every year. It will get but sorting is not correct. </p>
  
  <pre>
  SELECT Client,DispacthDate,Models,Model1,Model2,Model3
  FROM  (
          SELECT  Client
                  ,Concat(year(Audit_Date),' ',datename(month,Audit_Date)) as DispatchDate
                  ,Models
                  ,Count(Models) 'Units'
          FROM dbo.ABC
          GROUP BY Client,Concat(year(Audit_Date),' ',datename(month,Audit_Date)),Models
        ) abcd
  PIVOT(SUM(Units) FOR Models IN (Model1,Model2,Model3)) as P
  ORDER BY Client,DispatchDate
  </pre>
  
  <p>I'll get result set like this:</p>
  
  <pre>
   
  Client  DispatchDate    Model1  Model2  Model3
  Client1 2017 December   0   0   0
  Client1 2017 November   25  0   0
  Client1 2018 January    21  0   0
  Client1 2018 March       9  0   0
  Client2 2017 December    8  0   0
  Client2 2018 April       5  0   0
  Client2 2018 August      0  0   0
  Client2 2018 July        0  0   0
  Client2 2018 March       0  0   0
  Client3 2017 December    4  0   0
  Client3 2017 November   687 0   0
  Client3 2018 April       8  0   0
  Client3 2018 January     0  0   0
  
  
  </pre>
  
  <p>But Required Data Like:</p>
  
  <pre>
  Client  DispatchDate    Model1  Model2  Model3
  Client1 2018 January    21  0   0
  Client1 2018 March       9  0   0
  Client1 2017 November   25  0   0
  Client1 2017 December   0   0   0
  Client2 2018 March      0   0   0
  Client2 2018 April      5   0   0
  Client2 2018 July       0   0   0
  Client2 2018 August     0   0   0
  Client2 2017 December   8   0   0
  Client3 2018 January    0   0   0
  Client3 2018 April      8   0   0
  Client3 2017 November   687 0   0
  Client3 2017 December   4   0   0
  
  </pre>
  
  <p>Please Any one suggest me for my query.</p>