如何在ODBC SQLCommand表达式中传递SSIS变量? [英] How to pass SSIS variables in ODBC SQLCommand expression?

查看:395
本文介绍了如何在ODBC SQLCommand表达式中传递SSIS变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用通用表表达式将增量数据从ODBC服务器加载到SQL服务器. 在Dbeabver应用程序中运行查询时,将正确执行:

I'm trying to load incremental data from ODBC server to SQL server using common table expression. When running the query in the Dbeabver application, is executed correctly:

with test as
(
    SELECT userid,sum(goldbalance)
    FROM Server.events_live
    where eventTimestamp>=DATE '2016-01-01' + INTERVAL '-100 day'
    group by userid
    order by sum(goldbalance) desc)
)
select * from test

从ODBC源的sql命令表达式运行它时,由于语法错误而失败.它看起来如下:

when running it from an sql command expression of the ODBC source, it fails due to wrong syntax. It looks as follow:

with test as
(
    SELECT userid,sum(goldbalance)
    FROM deltadna.events_live
    where eventTimestamp>=DATE '"+@[User::datestring]+"' + INTERVAL '-100 day'
    group by userid
    order by sum(goldbalance) desc)
)
select * from test"

datestring变量获取服务器日期,并将其转换为yyyy-mm-dd格式的字符串.我通常使用这种方法从ADO.NET中提取数据,并且可以正常工作.

the datestring variable is getting the server date and convert it to string in the format yyyy-mm-dd. I'm usually use this method to pull data from ADO.NET and it works properly.

还有其他方法可以使用ssis变量从ODBC服务器中提取增量数据吗?

Is there any other way to pull incremental data from ODBC server using ssis variables?

推荐答案

  • 使用OLE DB
    • With OLE DB
    • 尝试下面的代码,它对我自己的SQL Server表有效:

      Try this code, it works for me with my own tables with SQL Server :

      SELECT userid,sum(goldbalance) AS SUMGOLD
      FROM deltadna.events_live
      WHERE eventTimestamp >= DATEADD(DAY, -100,CONVERT(DATE,?))
      GROUP BY userid
      ORDER BY SUMGOLD desc
      

      您必须在OLEDB Source Editor中单击Parameters来配置所需的内容.使用 '?'代表查询中的变量.

      You have to click on Parameters in the OLEDB Source Editor to configure what you need. Use the '?' to represent a variable in your query.

      如果查询是否过于复杂,请将其存储在存储过程中,并按以下方式调用它:

      If you query if too complicated, stored it in a stored procedure and call it like this:

      EXEC shema.storedProcedureName ?
      

      然后映射?"到您的变量@user :: DateString

      And map the '?' to your variable @user::DateString

      • 使用ODBC

      表达式在数据流属性"中的数据流之外. 选择expression属性,然后添加动态查询.

      The expressions are outside the data flow in Data Flow Properties. Select the expression property and add your dynamic query.

      您的表情将会

      "SELECT userid,sum(goldbalance) AS SumGold
      FROM deltadna.events_live
      where eventTimestamp>=DATE "+@[User::datestring]+" +INTERVAL '-100 day'
      group by userid
      order by SumGold desc"
      

      这篇关于如何在ODBC SQLCommand表达式中传递SSIS变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆