首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-11-13 
select 某个特定字段之外的所有字段值查询表某个字段之外的所有值,有什么好方法?想到先可以这样:selectnam

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 表名') 

热点排行
Bad Request.