How do I get structure of temp table then delete temp table. Is there a sp_helptext for temp tables? Finally is it possible to then delete temp table in same session or query
So, this helped me. It created the Table columns.
Select Column_Name + ' [' + DATA_TYPE + ']' +
case when Data_Type in ('numeric', 'varchar', 'char')
then '(' +
case
when DATA_TYPE = 'numeric' then CAST(numeric_precision as varchar(3)) + ',' + CAST(numeric_scale as varchar(3))
when DATA_TYPE = 'varchar' then CAST(CHARACTER_MAXIMUM_LENGTH as varchar(3))
when DATA_TYPE = 'char' then CAST(CHARACTER_MAXIMUM_LENGTH as varchar(3))
end
+ ')'
else ''
end
+ ','
, *
From tempdb.INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME LIKE '#MEHTEMPTABLE%'
All I then needed to do was copy these items into a Table Declaration
Declare @MyTable Table
(
--All columns here
)
That would've resolved my issue, but I was pressed for time