34,587
社区成员
发帖
与我相关
我的任务
分享
-->引用三楼的代码,得到的结果集字段出现的顺序跟原来一样加order by oclid就行了
declare @col varchar(1000)
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('表名') and name<>'排除的字段名'
set @col=stuff(@col,1,1,'')
exec('select '+@col+' from 表名')