Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get list of columns in a temp table in SQL Server

I am creating a temporary table on-the-fly using Select * Into #temp from SomeChangingSource in a stored procedure. I need to then list the resulting columns.

Handling this for a regular (permanent) table is as simple as:

select COLUMN_NAME 
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='TableName'

How do I handle this for a temporary table?

like image 272
John Joseph Avatar asked Dec 22 '16 18:12

John Joseph


1 Answers

Your were close. Just needed to point it to Tempdb.Sys.Columns

 Select * From  Tempdb.Sys.Columns Where Object_ID = Object_ID('tempdb..#TempTable')
like image 95
John Cappelletti Avatar answered Oct 04 '22 10:10

John Cappelletti