Link to home
Start Free TrialLog in
Avatar of OzarkSunshine
OzarkSunshine

asked on

Select column_name from INFORMATION.SCHEMA.COLUMNS not working with TEMP tables

I'm creating a global temp table using a random id and then trying to get column names from that table using INFORMATION_SCHEMA. Below is an example of what I'm doing --

SELECT 'JOHN' AS FIRST_NAME,'DAVIS' AS LAST_NAME      ,'CHICAGO' AS CITY INTO  [##E0404FF442A04AC7BCCEC3379FBC63]

select column_name from TEMPDB.INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='[##E0404FF442A04AC7BCCEC3379FBC63]'
This does not work, it returns nothing under column_name.  I can take that same table and copy it into another temp table, and it works.        

SELECT * INTO ##OUT_LABEL FROM [##E0404FF442A04AC7BCCEC3379FBC63]

select column_name from TEMPDB.INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='##OUT_LABEL'

column_name
FIRST_NAME
LAST_NAME
CITY

What am I missing here on why this is not working???
Avatar of OzarkSunshine
OzarkSunshine

ASKER

Actually figured it out... had to get it to drop the brackets in the original temp table  name.
SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial