title: sql rename all column names given a string with new column names
body: <p>I would like to rename all column names of a table given a string with new names separated by comma. Here be the string:</p>
  
  <pre><code>declare @str varchar(max)='A,B,C'
  </code></pre>
  
  <p>The number of columns in a table may vary, and appropriately the number of names in a string. So in a 5-column table the string would be <code>'A,B,C,D,E'</code>.</p>
  
  <p>I have a table with column names as:</p>
  
  <pre><code>col1 | col2 | col3
  </code></pre>
  
  <p>and in expected results I would like to have:</p>
  
  <pre><code>A | B | C
  </code></pre>
  
  <p><strong>Update</strong>
  I have tried to follow that path:</p>
  
  <pre><code>SELECT 
   ORDINAL_POSITION
  ,COLUMN_NAME
  FROM INFORMATION_SCHEMA.COLUMNS
  WHERE 
  TABLE_NAME = 'my_temp'
  order by ORDINAL_POSITION asc
  </code></pre>
  
  <p>but I do not know how to split @sql string so that it can be applied to results in the following way:</p>
  
  <pre><code>ORDINAL_POSITION  COLUMN_NAME  sql_string  
  1                 Col1         A  
  2                 Col2         B  
  3                 Col3         C   
  </code></pre>
  
  <p>Then I could easily create a string like:</p>
  
  <pre><code>dynamic_sql='EXEC sp_rename my_table.' + COLUMN_NAME +',' + sql_string +', ''COLUMN'''
  </code></pre>