参数未在 SSIS 包的运行时加载

发布于 2024-12-04 15:07:13 字数 441 浏览 0 评论 0原文

我有简单的 SSIS 包。我的来源是 sql 命令,如下:

  Select * from table1 where col in (select col from table2 where col3='VAL')

  For VAL I created the variable. and for subquery I created one more variable.

  Variable1=VAL

  variable2=select col from table2 where col3=Variable1

所以我的来源如下:

  Select * from table1 where col in (variable2)

当我运行包时,这不会替换。似乎 Variable2 未正确加载。

请指教。

I have simple SSIS package. My source is sql command as follows:

  Select * from table1 where col in (select col from table2 where col3='VAL')

  For VAL I created the variable. and for subquery I created one more variable.

  Variable1=VAL

  variable2=select col from table2 where col3=Variable1

So my source is as follows:

  Select * from table1 where col in (variable2)

When I run the package, this is not replacing. Seems to be the Variable2 is not loading properly.

Please advice.

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

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

发布评论

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

评论(1

策马西风 2024-12-11 15:07:13

首先,如果 col 是 table1 和 table2 之间的连接列,您可以重写查询,如下所示:

SELECT      *
FROM        dbo.Table1  T1
INNER JOIN  dbo.Table2  T2
ON          T1.Col      = T2.Col
WHERE       T2.Col3     = 'VAL'

我假设您在 OLE DB Source 或 ADO.NET Source 中使用此查询,并使用 SQL Command 选项读取它。

因此,将查询放入存储过程中,如下所示:

CREATE PROCEDURE dbo.GetData
(
    @Param1 NVARCHAR(50)
)
AS
BEGIN
    SET NOCOUNT ON;

    SELECT      T1.col
            ,   T2.col3
    FROM        dbo.Table1  T1
    INNER JOIN  dbo.Table2  T2
    ON          T1.Col      = T2.Col
    WHERE       T2.Col3     = @Param1
END

创建两个 SSIS 包变量来存储存储过程执行命令以及要传递的参数值。

Variables

在变量 StoredProcedure 的属性上,设置属性 EvaluateAsExpression > 为 True 并将表达式设置为 "EXEC dbo.GetData '" + @[User::Parameter] + "'"

Expression

使用如下所示的变量 StoredProcedure 将其作为变量传递给 OLE DB 源。每当变量Parameter中的值发生变化时,存储过程的执行命令也会随之变化。

OLE DB

First of all, if col is the joining column between table1 and table2, you can rewrite the query as shown below:

SELECT      *
FROM        dbo.Table1  T1
INNER JOIN  dbo.Table2  T2
ON          T1.Col      = T2.Col
WHERE       T2.Col3     = 'VAL'

I assume that you are using this query in the OLE DB Source or ADO.NET Source to read it using SQL Command option.

So, put your query in a stored procedure as shown below:

CREATE PROCEDURE dbo.GetData
(
    @Param1 NVARCHAR(50)
)
AS
BEGIN
    SET NOCOUNT ON;

    SELECT      T1.col
            ,   T2.col3
    FROM        dbo.Table1  T1
    INNER JOIN  dbo.Table2  T2
    ON          T1.Col      = T2.Col
    WHERE       T2.Col3     = @Param1
END

Create two SSIS package variables to store the stored procedure execution command and also the parameter value to be passed.

Variables

On the properties of the variable StoredProcedure, set the property EvaluateAsExpression to True and set the Expression to "EXEC dbo.GetData '" + @[User::Parameter] + "'"

Expression

Use the variable StoredProcedure as shown below to pass it as a variable to the OLE DB Source. Whenever the value in the variable Parameter changes, the stored procedure execution command will change accordingly.

OLE DB

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