当前位置: 代码迷 >> Sql Server >> select 排除列的有关问题
  详细解决方案

select 排除列的有关问题

热度:1   发布时间:2016-04-27 16:47:36.0
select 排除列的问题
表a有列   a1,a2,a3,a4……
现在想查询出除了a1列外其他所有列,除了这样写
select   a2,a3,a4....   from   a
之外还有其他更简便写法吗?

------解决方案--------------------
用动态:
declare @sql varchar(4000)
select @sql=isnull(@sql, ' ')+ ',[ '+name+ '] ' from syscolumns where id=object_id( '表名 ') and name!= 'a1 '
set @sql=left(@sql,len(@sql)-1)
exec( 'select '[email protected]+ ' from 表名 ')
------解决方案--------------------
别的办法~~有是有~~~~但你是为了简便~~~而不是为了解脱问题~~~所以.......
提示:
select name from syscolumns where id=object_id( '表名 ')
  相关解决方案