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 表名')
- 1 回答
- 0 关注
- 888 浏览
添加回答
举报
0/150
提交
取消