Within SQL Server 2005, I need to create a table dynamically based upon the rows returned from a query.
For example:
SELECT * FROM TableA
returns the following rows
- Forename
- Surname
- DOB
And I’d like a table created like so:
Forename, Surname, DOB.
I plan to use this procedure on a number of different sources therefore the returned rows will be different each time.
Many thanks
I would use
SELECT INTOin conjunction withPIVOT:See:
I don’t have access to SQL Server right now, but I would go for something like this (based on the links above):