使用执行SQL任务进行参数映射 [英] Parameter Mapping using an Execute SQL Task
问题描述
我试图创建一个临时表并将数据插入到foreach循环容器内的Execute SQL Task中的临时表中。
I am trying to create a temporary table and insert data into the temp table within an Execute SQL Task inside a foreach loop container.
以下是sql任务
IF OBJECT_ID('TEMPDB.DBO.#TEMP') IS NOT NULL
DROP TABLE #TEMP
GO
CREATE TABLE #TEMP
( ... );
INSERT INTO #TEMP
SELECT (...)
FROM table t1 INNER JOIN table2 t2
ON t1.id = t2.table1_id
WHERE t1.value = ?
我想在WHERE子句中有一个参数,但是每当尝试添加它时,都会出现此错误。
I want to have a parameter in the WHERE clause but whenever I try to add it I get this error.
多步OLE DB操作生成了错误。请检查每个OLE DB状态值(如果可用)。未完成任何工作。。可能的失败原因:查询问题, ResultSet属性未正确设置,参数未正确设置或连接未正确建立。
"Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly."
当我对值进行硬编码时
我在参数映射上做错了什么?
这是我的参数映射设置
Here are my parameter mapping settings
我也不是能够使用存储过程。
推荐答案
只需转到表达式
标签,如您提供的屏幕截图所示,并将以下表达式写入 SqlStatmentSource
属性
Just go to Expressions
Tab as shown in the screenshot you provided and write the following expression to SqlStatmentSource
property
"IF OBJECT_ID('TEMPDB.DBO.#TEMP') IS NOT NULL
DROP TABLE #TEMP
GO
CREATE TABLE #TEMP
( ... );
INSERT INTO #TEMP
SELECT (...)
FROM table t1 INNER JOIN table2 t2
ON t1.id = t2.table1_id
WHERE t1.value = '" + @[User::Where_Variable] + "'"
这篇关于使用执行SQL任务进行参数映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!