OLE DB 命令中存储过程的 SSIS 返回值

发布于 2024-07-13 00:54:47 字数 359 浏览 7 评论 0原文

我正在迁移必须使用已存在的存储过程插入的数据。 存储过程具有参数和插入行的 id 返回值(来自 select 语句)。 在 SSIS 中的 OLE DB 命令中,我可以调用存储过程,传递列值作为参数,并且我通常在存储过程上使用输出参数来处理“id”输出; 但我不确定当过程使用 select 返回 id 值时如何使用返回值来处理这个问题。 这是我之前使用过的示例,它有效,但我需要获取从选择返回的值:

exec dbo.uspInsertContactAddress
@Address = ?,
@ContactID = ?,
@DeliveryMethodId = ?,
@ID = ? output,
@Version = ? output

I am migrating data that has to be inserted using stored procedures which already exist. The stored procedures have parameters and a return value (from a select statement) of an id for the row inserted. Within an OLE DB Command in SSIS, I can call the stored procedure passing column values as the parameters and I usually use output parameters on the stored procedure to handle "id" output; but I am unsure how this can be handled with return values when the procedure uses a select to return the id value. Here is an example of what I have used before which works but I need to pick up the value returned from the select:

exec dbo.uspInsertContactAddress
@Address = ?,
@ContactID = ?,
@DeliveryMethodId = ?,
@ID = ? output,
@Version = ? output

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

豆芽 2024-07-20 00:54:47

我发现我可以做到这一点的方法实际上非常简单:

exec ? = dbo.StoredProc @param = ?, @param2 = ?

然后 @RETURN_VALUE 将出现在可用目标列上

The way I found I could do this which was actually quite simple:

exec ? = dbo.StoredProc @param = ?, @param2 = ?

and then a @RETURN_VALUE will appear on the Available Destination Columns

蛮可爱 2024-07-20 00:54:47

不要在 SqlCommand 属性中使用变量名,仅使用问号和输出参数的“OUT”或“OUTPUT”标签。

获取输出参数值的技巧是在 OLE DB 命令之前将派生列转换放入管道中,以引入列(映射到 SSIS 变量)来捕获过程结果。

有关详细概述,请参阅 OLEDB 命令转换和标识列带有如何执行此操作的屏幕截图。 另请参阅垃圾目标适配器,了解第一个链接中使用的垃圾目标。 它是一个方便的工具,可用于调试此类事情。

Don't use the variable names in the SqlCommand property, just the question marks and the "OUT" or "OUTPUT" label for the output parameters.

The trick for grabbing the output parameter value is to put a derived column transformation in the pipeline ahead of the OLE DB Command to introduce a column (mapped to an SSIS variable) to capture the procedure result.

See OLEDB Command Transformation And Identity Columns for a good overview with screen caps of how to do this. Also see Trash Destination Adapter for the Trash Destination used in the first link. It's a handy tool to have available for debugging things like this.

诗酒趁年少 2024-07-20 00:54:47

我一直在执行 SQL 任务中使用参数映射,并取得了很大的成功。 SQL 语句是“EXEC nameofstoredproc ?, ? OUTPUT”,其中问号指定参数的位置,如果参数是输出,则使用 OUTPUT。

您可以使用适当的变量名称、方向(输入、输出、ReturnValue)和数据类型来指定映射中的参数。 由于您的存储过程正在通过结果集返回您想要的数据,因此请指定变量收集 ID 和版本的方向作为 ReturnValue。 它应该适合你。

I have always used the parameter mapping within the Execute SQL Task with a lot of success. The SQL Statement is "EXEC nameofstoredproc ?, ? OUTPUT", with the question marks specifying the location of the parameters and OUTPUT if the parameter is an output.

You specify the parameters in the mapping with the appropriate variable name, direction (input, output, ReturnValue) and data type. Since your stored proc is returning the data you want via a result set, then specify the direction for the variables to collect the ID and version as ReturnValue. It should work just fine for you.

随心而道 2024-07-20 00:54:47

如果存储过程返回结果集,那么您需要捕获它:

DECLARE @results TABLE (
    [ID] INT NOT NULL
)

INSERT @results ([ID])
EXEC dbo.uspInsertContactAddress @Address = ?, @ContactID = ?, @DeliveryMethodId = ?, @ID = ? output, @Version = ? output

SELECT * FROM @results 

注意:我使用了 TABLE 变量。 您可能需要使用临时表,具体取决于您的 SQL Server 版本。

If the stored procedure returns a resultset, then you need to capture it:

DECLARE @results TABLE (
    [ID] INT NOT NULL
)

INSERT @results ([ID])
EXEC dbo.uspInsertContactAddress @Address = ?, @ContactID = ?, @DeliveryMethodId = ?, @ID = ? output, @Version = ? output

SELECT * FROM @results 

Note: I used a TABLE variable. You might need to use a temp table depending on your SQL Server version.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文