简体   繁体   English

SSIS中的错误执行SQL任务

[英]error in ssis execute sql task

I have placed a execute sql task inside the foreach loop container , where i want to execute the stored procedure name obtaining from the ssis user defined variable But i am not finding a right syntax to execute stored procedure name from variable. 我已经在foreach循环容器内放置了一个execute sql任务,在这里我想执行从sis用户定义的变量获取的存储过程名称,但是我没有找到从变量执行存储过程名称的正确语法。 and i want to pass input parameter to execute the stored procedure which is also a another dts variable Please can any one help to figure out the right syntax 我想传递输入参数来执行存储过程,这也是另一个dts变量,请提供任何帮助以找出正确的语法

在此处输入图片说明

Lets say you have two variables StoredProcedureName and ParameterValue 假设您有两个变量StoredProcedureNameParameterValue

Create a new variable called QueryString . 创建一个名为QueryString的新变量。 Open up the properties window by pressing F4 and then click on the variable name in the window that has list of variables. F4打开属性窗口,然后在具有变量列表的窗口中单击变量名称。 Set the EvaluateAsExpression property of your QueryString variable to True. 将您的QueryString变量的EvaluateAsExpression属性设置为True。

Then click the elliptical in Expression to open up the Expression Builder . 然后单击“ Expression的椭圆以打开“ 表达式生成器” Type the following expression 输入以下表达式

"Execute " + @[User::StoredProcedureName] + " @ParameterName = '" + @[User::ParameterValue]+ "'"

Click on Evaluate Expression and you should see 单击评估表达 ,您应该看到

Execute MyProcedure @ParameterName = 'SomeValue'

Assign this variable to your SourceVariable for the Execute SQL Task . 将该变量分配给SourceVariable ,以执行Execute SQL Task

You can build your string out as provided above but I would not start with it. 可以按照上面提供的方法构建字符串,但是我不会以它开头。 For one, it assumes everything is string and second it could conceivably open you up to sql injection (highly improbable, I agree) 首先,它假设所有内容都是字符串,其次它可能使您容易进行sql注入(非常不可能,我同意)

To actually use the native parameter mapping for ADO.NET you need to use the @PlaceHolder for your variable substitution. 要实际使用ADO.NET的本机参数映射,您需要使用@PlaceHolder进行变量替换。 Based on your screenshot, the value of @[User::StoredProcedureName] would need to have the format of EXECUTE schema.ProcName @ParameterName Otherwise, you're looking at cobbling the expression from @Raj More's example without the =... piece 根据您的屏幕截图,@ [User :: StoredProcedureName]的值将需要具有EXECUTE schema.ProcName @ParameterName的格式EXECUTE schema.ProcName @ParameterName否则,您将需要从@Raj More的示例中折叠表达式,而无需使用=...

在此处输入图片说明

Mapping is as simple as the following. 映射如下所示。 Ensure you select the correct Data Types and Parameter Names to correlate with your query. 确保选择正确的数据类型和参数名称以与您的查询相关联。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM