Wednesday, April 13, 2011

[Code] Using INFORMATION_SCHEMA with temp tables.

Was recently trying to parse a temp table and do things based on the columns. I'd come up with this....


SELECT * FROM tempdb.INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME LIKE '#yourtemptablehere%'


But then I came across this post from Michael Valentine Jones (a pseudonym?), on the SQLTeam forums. Many thanks, Michael

select
*
from
tempdb.information_schema.columns
where
object_id('tempdb..#yourtemptablehere') = object_id('tempdb..'+TABLE_NAME)

No comments: