title: Predefined column names in SQL Server pivot table
body: <p>the other day I opened a topic here in StackOverflow (<a href="https://stackoverflow.com/questions/4663698/how-can-i-display-a-consolidated-version-of-my-sql-server-table">stackoverflow.com/questions/4663698/how-can-i-display-a-consolidated-version-of-my-sql-server-table</a>). At that time I needed help on how to show data on a pivot table. From the help I got here in the forum, my research led me to this page about dynamic SQL: <a href="http://www.sommarskog.se/dynamic_sql.html" rel="nofollow noreferrer">www.sommarskog.se/dynamic_sql.html</a>. And then it led me to this awesome SQL script by Itzik Ben-Gan that will create a stored procedure that outputs a pivot table exactly the way I want: <a href="http://sommarskog.se/pivot_sp.sp" rel="nofollow noreferrer">sommarskog.se/pivot_sp.sp</a>.</p>
  
  <p>Well, almost. I need one change in this stored procedure. Instead of having dynamic column names pulled from the @on_cols variable in the SPROC, I need the output table to hold generic column names in simple ASC order. Could be, for example, col1, col2, col3, col4 ... The dynamic column names are a problem for me. So I need them named by their index in the order they appear. I have tried all sorts of things changing this great SQL script, but it won't work.</p>
  
  <p>I did not paste the code from the author because it is too long, but the link <a href="http://sommarskog.se/pivot_sp.sp" rel="nofollow noreferrer">above</a> will get us there.</p>
  
  <p>Any help appreciated. Thank you very much</p>