当前位置: 代码迷 >> Sql Server >> select 某个特定字段以外的所有字段值
  详细解决方案

select 某个特定字段以外的所有字段值

热度:100   发布时间:2016-04-25 01:13:45.0
select 某个特定字段之外的所有字段值
查询表某个字段之外的所有值,有什么好方法?想到先可以这样:
select name from syscolumns where id=object_id( '表名称 ') and name <> 'photo '
这样查询到除了字段“photo ”之外的所有字段名称,但怎样拼写个语句查询出值呢?

------解决方案--------------------
SQL code
declare @sql varchar(max)select @sql = isnull(','+@sql,'')+name from syscolumns where id=object_id( '表名称 ') and name <> 'photo 'set @sql = 'select ' + @sql + ' from 表名称 where ... 'exec(@sql)
------解决方案--------------------
SQL code
declare @col varchar(1000)select @col=isnull(@col+',','')+name from syscolumns where id=object_id('表名') and name<>'排除的字段名' order by colidexec('select '+@col+' from 表名')
  相关解决方案