How do I sort a SQL Server 2008 pivot result columns and rows?
<p>I'm using <a href="https://stackoverflow.com/questions/10404348/sql-server-dynamic-pivot-query">This</a> to get pivot results for a table. But I want the resulting columns and rows both in a specific order. So the rows would be sorted by <code>CDATE</code> and the columns would be <code>CDATE</code>, <code>BALANCE</code>, then the <code>DATE</code> columns.</p>

<pre><code>CDATE      | BALANCE | 04-2007 | 05-2007 | 06-2007 | TRANS TOT
2003-01-15 | 5000    | 60      | 0       | 0       | 60 
2003-02-15 | 4000    | 40      | 0       | 0       | 40
2003-03-15 | 5500    | 20      | 15      | 15      | 50 
</code></pre>