当前位置:Gxlcms > 数据库问题 > Execute SQL Task 参数和变量的映射

Execute SQL Task 参数和变量的映射

时间:2021-07-01 10:21:17 帮助过:3人阅读

? 0, 1, 2, 3, … SELECT FirstName, LastName, Title FROM Person.Contact WHERE ContactID = ?

1,执行SQL查询语句

楼主在实际开发中,最常用的Connection Type是OLEDB,设置Task的ConnectionType为OLE DB,在SQLStatement属性中使用 ? 来标记一个参数,? 叫做参数标记(Parameter Marker)。

  1. <span style="color: #0000ff;">select</span><span style="color: #000000;"> ID,c1
  2. </span><span style="color: #0000ff;">from</span><span style="color: #000000;"> dbo.dt_test
  3. </span><span style="color: #0000ff;">where</span> c1<span style="color: #808080;">=</span>?

技术分享

使用SSIS 变量(Variable)为参数赋值,Parameter Name必须是0,1,2等数字

技术分享

2,执行SP,设置参数的方向

使用Execute SQL Task执行SP时,参数映射的Direction属性使用Input,Output和Returnvalue 分别表示:输入参数,输出参数和SP的返回值

  1. <span style="color: #0000ff;">declare</span> <span style="color: #008000;">@return_value</span> <span style="color: #0000ff;">int</span>
  2. <span style="color: #0000ff;">declare</span> <span style="color: #008000;">@output_var</span> <span style="color: #0000ff;">int</span>
  3. <span style="color: #0000ff;">declare</span> <span style="color: #008000;">@input_var</span> <span style="color: #0000ff;">int</span>
  4. <span style="color: #0000ff;">set</span> <span style="color: #008000;">@input_var</span><span style="color: #808080;">=</span><span style="color: #800000; font-weight: bold;">1<br></span>
  5. <span style="color: #0000ff;">exec</span> <span style="color: #008000;">@return_value</span><span style="color: #808080;">=</span>dbo.usp_test <span style="color: #008000;">@para1</span><span style="color: #808080;">=</span><span style="color: #008000;">@input_var</span>, <span style="color: #008000;">@para2</span><span style="color: #808080;">=</span> <span style="color: #008000;">@output_var</span> output;

使用OLEDB Connection Manager,使用 ? 表示一个参数,如图

技术分享

在Parameter Mapping Tab中设置参数映射:

  • 第一个参数是SP的返回值,Direction 选择 Returnvalue,Parameter Name 是 0;
  • 第二个参数是SP的输入参数,Direction 选择 Input,Parameter Name 是 1;
  • 第三个参数是SP的输出参数,Direction 选择 Output,Parameter Name 是 2;

 技术分享

 

参考文档:

SQL Server SP2 – What’s new for SSIS

Map Query Parameters to Variables in an Execute SQL Task

Parameters and Return Codes in the Execute SQL Task

Execute SQL Task 参数和变量的映射

标签:

人气教程排行