Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在 sql server 2008 中编写一个可以将表名作为变量的函数。
例如:
create function test(@tbl varchar(50)) .. select * from @tbl ..
您可以从变量执行 SQL 语句:
在功能上:
DECLARE @var AS VARCHAR(500) SET @var = 'SELECT * FROM ' + @tbl EXECUTE (@var)