sqlsever 表有100个字段,查询前43个。
发布网友
发布时间:2024-09-27 15:29
我来回答
共1个回答
热心网友
时间:2024-09-27 18:31
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 表名')