How to pass SSIS variables in ODBC SQLCommand expression?(如何在 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
试试这个代码,它适用于我自己的 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 源代码编辑器中单击参数以配置您需要的内容.使用 '?'表示查询中的变量.
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
表达式在数据流属性中的数据流之外.选择表达式属性并添加您的动态查询.
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 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 ODBC SQLCommand 表达式中传递 SSIS 变量?


- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 更改自动增量起始编号? 2021-01-01