获取表作为变量 [英] Get Table as A variable
本文介绍了获取表作为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个名为test的表,我想在变量中获取表实体本身,所以我可以在join语句中使用它
注意:
i在运行时有表名,我想把表本身放在一个变量中。
在此先感谢:)
Hi everyone,
I have a table with name "test" and i want to get table entity itself in a variable so i can use it in join statement
Note:
i have table name in run-time and i want to get the table itself in a variable.
Thanks in Advance :)
推荐答案
好的,如果我理解你的问题,那么你可以使用动态sql,如下所示:
Ok, so if I understood your question correctly, then you could use dynamic sql, something like following:
declare @name nvarchar(50)
set @name = (select Name from Lookups where Lookups.ID = 4)
execute ('select * from ' + @name)
这根本没有意义。你的问题是一个SQL问题。您可以在连接语句中使用该表,那里没有问题。如果您有实际问题,则根本不清楚。
This makes no sense at all. Your question is a SQL question. You can use the table in a join statement, there''s no issue there. If you have an actual issue, it''s not clear at all.
首先感谢:)
Thanks firstly :)
declare @name nvarchar(50)
set @name = (select Name from Lookups where Lookups.ID = 4)
NOW [@name = MyTableName说Items]
然后我想做类似的事情:
NOW [@name = MyTableName say "Items"]
then i want to do something like:
select * from @name
在任何加入声明中使用@name
谢谢
OR
using @name in any join statement
Thanks
这篇关于获取表作为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文