为了账号安全,请及时绑定邮箱和手机立即绑定

sqlsever 表有100个字段,查询前43个。

sqlsever 表有100个字段,查询前43个。

MMMHUHU 2018-07-05 10:10:31
sqlsever 表有100个字段,查询前43个。select 语句该怎么写?不要说select后面把那43个字段都列出来。
查看完整描述

1 回答

?
ITMISS

TA贡献1871条经验 获得超8个赞

select top 43 IDENTITY(int,1,1)AID,name into #t from syscolumns

where id=(select id from sysobjects where name='表名') order by colid
declare @AID int,@Sel varchar(1000)
select @AID=1,@Sel=''
while @AID<=43
begin
select @Sel=case when @Sel='' then name else @Sel+','+name end from #t Where AID=@AID
set @AID=@AID+1
end
exec('select '+ @Sel + ' From 表名')

查看完整回答
反对 回复 2018-08-17
  • 1 回答
  • 0 关注
  • 844 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信