sql 通配符

anwsp 2009-03-06 03:29:37
假设某表有很多字段a,b,。。。。
select * from tb 可以取出所有字段
但是目前不需要a字段,其余全要,有简便方法吗?
...全文
138 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
htl258_Tony 2009-03-07
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 josy 的回复:]
SQL codedeclare @col varchar(1000)
set @col=''
select @col=@col+','+name from syscolumns where id=object_id('表名') and name<>'排除的字段名'
set @col=stuff(@col,1,1,'')
exec('select '+@col+' from 表名')



不过这样得到的结果集字段出现的顺序可能跟原来不一样
[/Quote]

-->引用三楼的代码,得到的结果集字段出现的顺序跟原来一样加order by oclid就行了
declare @col varchar(1000)
set @col=''
select @col=@col+','+name from syscolumns where id=object_id('表名') and name<>'排除的字段名' order by colid
set @col=stuff(@col,1,1,'')
exec('select '+@col+' from 表名')
qizhengsheng 2009-03-07
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 liusong_china 的回复:]
引用 3 楼 josy 的回复:
SQL codedeclare @col varchar(1000)
set @col=''
select @col=@col+','+name from syscolumns where id=object_id('表名') and name <>'排除的字段名'
set @col=stuff(@col,1,1,'')
exec('select '+@col+' from 表名')


不过这样得到的结果集字段出现的顺序可能跟原来不一样


---------
select @col=@col+','+name from syscolumns where id=object_id('表名') and name <>'排除的字段名'…
[/Quote]

wzy4850 2009-03-06
  • 打赏
  • 举报
回复
直接就去掉了?
zijiezhuang 2009-03-06
  • 打赏
  • 举报
回复
select * into# from tb
alter table # drop column a
select * from #
zijiezhuang 2009-03-06
  • 打赏
  • 举报
回复
select * from tb 放到临时表,删掉A字段,再用select * from 临时表 这算是个思路吧。
anwsp 2009-03-06
  • 打赏
  • 举报
回复
无奈
肥龙上天 2009-03-06
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 htl258 的回复:]
引用楼主 jroc123 的帖子:
假设某表有很多字段a,b,。。。。
select * from tb 可以取出所有字段
但是目前不需要a字段,其余全要,有简便方法吗?
有方法,不简便
[/Quote]
这里好像不能使用通配符吧,关注一个
liusong_china 2009-03-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 josy 的回复:]
SQL codedeclare @col varchar(1000)
set @col=''
select @col=@col+','+name from syscolumns where id=object_id('表名') and name<>'排除的字段名'
set @col=stuff(@col,1,1,'')
exec('select '+@col+' from 表名')



不过这样得到的结果集字段出现的顺序可能跟原来不一样
[/Quote]

---------
select @col=@col+','+name from syscolumns where id=object_id('表名') and name<>'排除的字段名' order by colorder
htl258_Tony 2009-03-06
  • 打赏
  • 举报
回复
[Quote=引用楼主 jroc123 的帖子:]
假设某表有很多字段a,b,。。。。
select * from tb 可以取出所有字段
但是目前不需要a字段,其余全要,有简便方法吗?
[/Quote]有方法,不简便
jkfh126 2009-03-06
  • 打赏
  • 举报
回复
[^a]

好像是这个。
anwsp 2009-03-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 josy 的回复:]
SQL codedeclare @col varchar(1000)
set @col=''
select @col=@col+','+name from syscolumns where id=object_id('表名') and name<>'排除的字段名'
set @col=stuff(@col,1,1,'')
exec('select '+@col+' from 表名')



不过这样得到的结果集字段出现的顺序可能跟原来不一样
[/Quote]

好像也不简单
百年树人 2009-03-06
  • 打赏
  • 举报
回复
declare @col varchar(1000)
set @col=''
select @col=@col+','+name from syscolumns where id=object_id('表名') and name<>'排除的字段名'
set @col=stuff(@col,1,1,'')
exec('select '+@col+' from 表名')


不过这样得到的结果集字段出现的顺序可能跟原来不一样
小豆好好 2009-03-06
  • 打赏
  • 举报
回复
Mark
sdhdy 2009-03-06
  • 打赏
  • 举报
回复
只能把除了字段a的都列出来。

34,587

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧