Stored Procedure that has table argument in T-SQL

二次信任 提交于 2019-12-02 18:36:06

问题


Table Argument as OUTPUT

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?

thanks!


回答1:


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

After comment, a table valued parameter can not be declared OUTPUT. From CREATE PROC

A table-value data type cannot be specified as an OUTPUT parameter of a procedure.



来源:https://stackoverflow.com/questions/16851391/stored-procedure-that-has-table-argument-in-t-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!