是否可以根据另一个变量的值声明变量名?
见下面的代码:
declare @x int = 1
declare @y nvarchar(255)
while (@x) < (select rd.TimeBucket.value( 'count(/buckets/bucket)', 'nvarchar(255)' ) from DIM_FM_SR_REPORT_DEFINITION rd)
begin
set @y = '@bucket' + cast(@x as nvarchar(2))
declare @y as
set @x = @x + 1;
end
当前变量@y
正在存储我需要使用的值,声明一个新的变量名。
所以最后,我应该最终得到变量:
bucket1
bucket2
bucket3
bucket4
bucket5
bucket6
bucket7
bucket8
bucket9
bucket10
bucket11
bucket12