我现在有个行列转换后的动态表,不知道它的具体列,我将执行的结果集放在了全局临时表A中,然后A再和其他表连接聚合,现在我想要A中某列外的其他列,能实现吗?
解决方案 »
- 求各位一个SQL语句如何写
- 请问rollback transaction是什么意思?
- 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。
- 简单问题,大家帮忙呀!!!
- SQL2005安装不上sp1补丁!
- 这个存储过程怎么改?---------[高手请进]
- 我想用一个语句在插入一个记录时将RootID设置为PostID,怎样才行?
- XXXXXXXXXXXXXXXXXXX为什么我的SQL server(正版)可以启动,但SQL server Agent不能启动呢?
- nononono兄,那句SQL根本就没办法再优化了,我白花了50分
- 去那里找sql advantage
- 怎么将字符串数组转为整数型数组
- 对我而言比较难的一个查询语句,请高手解决,一定解决呀!!!!!
set @col=''
select @col=@col+','+name from syscolumns where id=object_id('表名') and name<>'排除的字段名' order by colid
set @col=stuff(@col,1,1,'')
exec('select '+@col+' from 表名')
set @col=''
select @col=@col+','+name from syscolumns where id=object_id('表名') and name<>'排除的字段名' order by colid
set @col=stuff(@col,1,1,'')
exec('select '+@col+' from 表名')
declare @col varchar(1000)
set @col=''
select @col=@col+','+name from syscolumns where id=object_id('##monthReport') and name<>'shop' order by colid
set @col=stuff(@col,1,1,'')
print @col 我可以select 出数据,但在syscolumns 中没有##monthReport
我是菜鸟,请教
你把这个换成你库里的表名 试试
难道临时表的列信息不是存储在syscolumns里吗?
呃~~
## 在tempdb 里,你要去那才能查到
谢谢,但现在需要的是##monthReport的列信息,然后组合成一个查询串
(
col1 int,
col2 int,
col3 int,
col4 int,
col5 int
)insert into ##tb
select 1,2,3,4,5 union all
select 2,3,4,5,6 union all
select 3,4,5,6,7 union all
select 4,5,6,7,8use tempdb
declare @col varchar(1000)
set @col=''
select @col=@col+','+name from sys.columns where object_id=object_id('##tb') and name<>'col2' order by column_id
set @col=stuff(@col,1,1,'')
--print @col
exec('select '+@col+' from ##tb')col1 col3 col4 col5
----------- ----------- ----------- -----------
1 3 4 5
2 4 5 6
3 5 6 7
4 6 7 8(4 row(s) affected)
使用tempdb下的sys.columns视图。