Determine column names of dynamic query result set
Posted on 2004-04-06
I need to get the column names (and hopefully datatypes) of a result set generated by a dynamic query. The query is stored in a varchar variable. For example:
DECLARE @query VARCHAR(1024);
set @query = 'Select * from my_table'
Since @query could be anything, including a result set based on multiple joins, I have no way of determining column names from SYSCOLUMNS.
Ideally, I would like a result set of column names (in a single column).