PHP就像T-SQL中的$$ var一样(SQL Server 2008)

时间:2022-11-05 00:55:43

Is there any way to execute something like php $$var ..?

有没有办法执行像php $$ var ..?

Which will make the value of a var as var name.

这将使var的值成为var名称。

I have been googling for many hours ant cant find any that satisfy my needs.

我一直在谷歌搜索几个小时,无法找到任何满足我的需求。

Thanks.

edit:

currently what I want to achieve is something similar to this

目前我想要达到的目标与此类似

declare @table1 table(Name Varchar(100))
declare @table2 table(Name Varchar(100))
...
declare @table10 table(Name Varchar(100))

declare @int1 int
set @int1 = 0
while @int1 < 10
begin
select @[table + @int1]
END

1 个解决方案

#1


0  

Since the example in the question isn't valid T-SQL, it's not clear whether you want to select the value of @[table + @int1], or from the table (i.e. select name from @[table + @int1]) - I'm assuming here that it's the second one.

由于问题中的示例不是有效的T-SQL,因此不清楚是要选择@ [table + @ int1]的值,还是从表中选择(即从@ [table + @ int1]中选择名称) - 我在这里假设它是第二个。

One approach would be to have a single table with an indicator column classifying the rows:

一种方法是使用一个带有指标列的表来对行进行分类:

declare @table table(Name Varchar(100), groupid int)
...

declare @int1 int
set @int1 = 0
while @int1 < 10
begin
  select name from @table WHERE groupid = @int1
  set @int1 = @int1 + 1
end

#1


0  

Since the example in the question isn't valid T-SQL, it's not clear whether you want to select the value of @[table + @int1], or from the table (i.e. select name from @[table + @int1]) - I'm assuming here that it's the second one.

由于问题中的示例不是有效的T-SQL,因此不清楚是要选择@ [table + @ int1]的值,还是从表中选择(即从@ [table + @ int1]中选择名称) - 我在这里假设它是第二个。

One approach would be to have a single table with an indicator column classifying the rows:

一种方法是使用一个带有指标列的表来对行进行分类:

declare @table table(Name Varchar(100), groupid int)
...

declare @int1 int
set @int1 = 0
while @int1 < 10
begin
  select name from @table WHERE groupid = @int1
  set @int1 = @int1 + 1
end