How to retrieve field names from temporary table (SQL Server 2008) How to retrieve field names from temporary table (SQL Server 2008) sql sql

How to retrieve field names from temporary table (SQL Server 2008)


select * from tempdb.sys.columns where object_id =object_id('tempdb..#mytemptable');


select * from tempdb.INFORMATION_SCHEMA.COLUMNSwhere table_name like '#MyTempTable%'


To use information_schema and not collide with other sessions:

select * from tempdb.INFORMATION_SCHEMA.COLUMNSwhere table_name =    object_name(        object_id('tempdb..#test'),        (select database_id from sys.databases where name = 'tempdb'))