Im trying to execute a SQL query that will rename the columns of a table with the text from the first recordset in a table.
My table looks like this:
COL1 | COL2 | COL3 | COL4 | COL5 | COL6
REASON |ITEMDATE|ITEMTIME|SITENAME| EVENT | RPM
tstamp |12-11-07| 24:12 | Spain1 |Shutdwn | 1000
tstamp |13-11-07| 02:22 | Spain1 |Startup | 1050
And I would like to rename the columns like this:
REASON |ITEMDATE|ITEMTIME|SITENAME| EVENT | RPM
tstamp |12-11-07| 24:12 | Spain1 |Shutdwn | 1000
tstamp |13-11-07| 02:22 | Spain1 |Startup | 1050
This procedure will do what you need. You can run it as follows:
Note that the procedure assumes that the “first” row is the physical first row on disk. Since this can change depending on which field the clustered index on the table uses it is not 100% guaranteed.
The code for the procedure: