是否可以将表名传递给存储过程并在没有 Exec 函数的情况下使用它? [英] Is it possible to pass a table name into a stored proc and use it without the Exec Function?
问题描述
我想创建一个 SP 或 UDF,在其中我提供一个表和列名作为参数,并且它对该目标执行某些操作.我使用的是 Sql Server 2005
I would like to create a SP or UDF where I supply a table and column name as a parameter and it does something to that target. I'm using Sql Server 2005
琐碎我正在尝试完成的示例:
Trivial Example of what I'm trying to accomplish:
CREATE FUNCTION Example (@TableName AS VARCHAR(100))
RETURNS TABLE
AS
BEGIN
SELECT *
INTO #temp
FROM @TableName
RETURN #temp
END
这个例子只是为了说明我试图通过将表名作为参数传递来完成什么.
The example is just something trivial to illustrate what I'm trying to accomplish in terms of passing the Table name as a parameter.
这是否可以不连接字符串并调用 EXEC 函数?
Is this possible to do w/o concatinating strings and calling the EXEC function?
最终,我正在尝试转换 这个问题的答案变成可重复使用的东西.
Ultimately, I'm trying to convert the answer from this question into something reusable.
推荐答案
这充满了 SQL 注入的味道.您仍然需要使用 EXEC 来执行此操作.
This reeks of SQL injection. You would still need to use EXEC to do this.
这篇关于是否可以将表名传递给存储过程并在没有 Exec 函数的情况下使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!