T-SQL中具有表参数的存储过程
问题描述:
我想将表变量传递到以表参数作为输出的过程中, 但不是只读的!我希望能够在PROC中修改该参数. 这可能吗? 如果不可能的话,还有另一种方法吗?
I want to pass a table variable into a procedure that has table argument as output, but not as read only! I want to be able to modify that argument inside the PROC. Is this possible? If it's not possible, is there another way to do this?
谢谢!
答
您必须将表值参数复制到表变量或临时表中
You'd have to copy the table valued parameter into a table variable or temp table
CREATE PROC DoStuff
@tvp SomeTableType READONLY
AS
..
SELECT * INTO #LocalCopy FROM @tvp; -- take local copy
...
DoStuff -- do processing on the input
...
SELECT ... FROM LocalCopy; --return results to client
GO
注释后,不能将表值参数声明为OUTPUT.从创建程序
After comment, a table valued parameter can not be declared OUTPUT. From CREATE PROC
不能将表值数据类型指定为过程的OUTPUT参数.
A table-value data type cannot be specified as an OUTPUT parameter of a procedure.