|
我们在写sql查询中,通常选取字段都是select 字段1,字段2,字段3....... from 表,如果有很多字段,又不想要其中的一个,有没有办法能 select 非(字段1) from 表 查到其他字段的内容呢,把字段1去掉,答案是有的,来看下面的方法吧
declare @s nvarchar(1000) set @s='' select @s=@s+','+quotename(Name) from syscolumns where ID=object_id('表') and Name not in('不要的列名') select @s=stuff(@s,1,1,'') print @s exec('select '+@s+' from 表')<PRE></PRE>
declare @s nvarchar(1000) set @s='' select @s=@s+','+quotename(Name) from syscolumns where ID=object_id('表') and Name not in('不要的列名') select @s=stuff(@s,1,1,'') print @s
exec('select '+@s+' from 表')
|