您的位置:首页 > 数据库

SQL中查询有很多字段,就不想要其中一个的方法

2008-07-30 11:09 609 查看
在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 表')[code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐