नीचे दिए गए कोड का प्रयास करें
declare @a int =21
Declare @sql varchar(max)='select *,'
while @a <32
begin
set @sql = @sql + cast(@a as varchar) + ' as D' + cast(@a as varchar) + ' ,'
set @a = @a+1
end
set @sql = substring(@sql,0,len(@sql)-1) + ' from tbl1'
exec( @sql)