当前位置: 代码迷 >> Sql Server >> 怎么读出临时表的列名?(建临时表时,临时表的列名没有固定)
  详细解决方案

怎么读出临时表的列名?(建临时表时,临时表的列名没有固定)

热度:142   发布时间:2016-04-27 19:38:07.0
如何读出临时表的列名?(建临时表时,临时表的列名没有固定)
如何读出临时表的列名?(建临时表时,临时表的列名没有固定)
用以下的语句没有用啊。
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 行)
*/
  相关解决方案