I'm using SQL Server 2008. Say I create a temporary table like this one:
create table #MyTempTable (col1 int,col2 varchar(10))
How can I retrieve the list of fields dynamically? I would like to see something like this:
Fields: col1 col2
I was thinking of querying sys.columns but it doesn't seem to store any info about temporary tables. Any ideas?
To get only columns name you can use this query below: SELECT * FROM tempdb. sys. columns WHERE [object_id] = OBJECT_ID(N'tempdb..
The following query will give the table's column names: SELECT column_name FROM INFORMATION_SCHEMA. COLUMNS. WHERE TABLE_NAME = 'News'
You cannot create and drop the #TEMP table within the CTE query.
select * from tempdb.sys.columns where object_id = object_id('tempdb..#mytemptable');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With