title: How do I sort or order month in Dynamic Pivot in MMM/YYYY format
body: <blockquote>
    <p>I have the following tale</p>
  </blockquote>
  
  <p><img src="https://i.stack.imgur.com/AxTMZ.jpg" alt="enter image description here"></p>
  
  <p>I could maintain the order of column with the help of following code</p>
  
  <pre><code>select @cols = STUFF((SELECT distinct ',' + QUOTENAME(LOGDATE) 
                 from #TEMP                    
                 FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)') ,1,1,'')
  </code></pre>
  
  <p>But how can I maintain the date in the format Dec/2013, Jan/2013, Feb/2013 ?</p>
  
  <p><img src="https://i.stack.imgur.com/XPtrD.jpg" alt="enter image description here"></p>
  
  <pre><code>set @query = 'SELECT * from 
              (
                  select name,logdate,value from #table                    
             ) x
              pivot 
              (
                   sum(value)
                  for logdate in (' + @cols + ')
              ) p '
  </code></pre>