日期:2014-05-18  浏览次数:20483 次

如何读出临时表的列名?(建临时表时,临时表的列名没有固定)
如何读出临时表的列名?(建临时表时,临时表的列名没有固定)
用以下的语句没有用啊。
select   name   from   syscolumns     where   id=object_id( '#TmpSub ')

------解决方案--------------------
select * from tempdb.dbo.syscolumns where id=object_id( 'tempdb.dbo.#TmpSub ')

------解决方案--------------------
select a = '1 ' into #t
select * from #t
select name from tempdb.dbo.syscolumns where id=object_id(N 'tempdb.dbo.#t ')
drop table #t
--------------------------------


(影響 1 個資料列)

a
----
1

(影響 1 個資料列)

name
--------------------------------------------------------
a

(影響 1 個資料列)

------解决方案--------------------
create table #tmp(colname varchar(10))
select name from tempdb.dbo.syscolumns where id = object_id( 'tempdb.dbo.#Tmp ')

drop table #tmp

/*
name
--------------------
colname

(所影响的行数为 1 行)
*/