while @n<=3
begin
set @sql='select '+ltrim(@id)+ltrim(@n)
exec(@sql)
end
------其他解决方案-------------------- while @n<=3
begin
set @sql=@sql+'select @id'+@n+';'
end
exec(@sql) ------其他解决方案-------------------- declare @campaign1 varchar(3),@campaign2 varchar(3),@id int,@n varchar(1),@sql varchar(100),@campaign varchar(10)
set @campaign1='T2m'
set @campaign2='T3m'
set @id=1
set @campaign='@campaign'
while @id<=3
begin
set @n=@id
set @sql='select @campaign='+ltrim(@campaign)+ltrim(@n)
exec(@sql)
set @id=@id+1
end