查询问题,马上解贴!不够再加

niaoren 2003-11-20 04:25:05
我现在有N个字段,有10个是固定的,
现在我要查询除去这10个字段的其他所有字段。
望大家帮我解决
...全文
16 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
niaoren 2003-11-20
  • 打赏
  • 举报
回复
谢谢,结贴
zjcxc 2003-11-20
  • 打赏
  • 举报
回复
--改为下面的就行了.

declare @s varchar(8000)
set @s=''
select @s=@s+','+name from syscolumns where object_id('要查询的表名')=id
and name not in('要排除的字段1','要排除的字段2',...'要排除的字段10')
order by colid --加上这句就行了
set @s=substring(@s,2,8000)
exec('select '+@s+' from 要查询的表名')
niaoren 2003-11-20
  • 打赏
  • 举报
回复
谢谢大家,这个问题解决了
但是其他字段查询出来后就自动排序了
我想保持原来的顺序,不知道能否解决
麻烦各位了
niaoren 2003-11-20
  • 打赏
  • 举报
回复
正在调试中,先谢谢了
tanys 2003-11-20
  • 打赏
  • 举报
回复
关注
zjcxc 2003-11-20
  • 打赏
  • 举报
回复
declare @s varchar(8000)
set @s=''
select @s=@s+','+name from syscolumns where object_id('要查询的表名')=id
and name not in('要排除的字段1','要排除的字段2',...'要排除的字段10')
set @s=substring(@s,2,8000)
exec('select '+@s+' from 要查询的表名')
txlicenhe 2003-11-20
  • 打赏
  • 举报
回复
declare @ varchar(8000)
set @=''
select @=@+rtrim(name)+',' from syscolumns where id=object_id('你的表名') and name not in ('字段1','字段2',...'字段10')
set @=left(@,len(@)-1)

exec('select '+@+' from 你的表名')
pengdali 2003-11-20
  • 打赏
  • 举报
回复
declare @ varchar(8000)
set @=''
select @=@+rtrim(name)+',' from syscolumns where id=object_id('你的表名') and name not in ('你不要的列名1','你不要的列名2')
set @=left(@,len(@)-1)
exec('select '+@+' from 你的表名')
txlicenhe 2003-11-20
  • 打赏
  • 举报
回复
declare @ varchar(8000)
set @=''
select @=@+rtrim(name)+',' from syscolumns where id=object_id('你的表名') and name not in '你不要的10个字段'
set @=left(@,len(@)-1)

exec('select '+@+' from 你的表名')

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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