SSIS-通过单个 SQL 任务设置多个变量 [英] SSIS- Set Multiple variables via a single SQL task
问题描述
我正在尝试将多个变量设置为返回单行多列的 SQL 查询的结果.SQL语句格式为:
I'm trying to set multiple variables to the result of an SQL Query that returns a single row with multiple columns. The SQL statement is in the format of:
SELECT top 1
a,
b,
c = x + y,
d
FROM tablename
WHERE aSwitch = 1
所以我希望使用执行 SQL 查询"任务,该任务将使用查询结果设置 4 个包变量.
So I wish to use an 'Execute SQL Query' task which will set 4 package variables with the results of the query.
例如,如果查询的结果是:
For example, if the results of the query were:
| a | b | c | d |
-------------------------------------
| duck | cow | rabbit | 42 |
那么执行后变量的状态将是:
Then the state of the variables after execution would be:
var1 = duck
var2 = cow
var3 = rabbit
var4 = 42
有什么想法吗?
(使用 VS/SQL 2005)
(using VS/SQL 2005)
推荐答案
在SQL任务中,在General菜单下,将ResultSet属性设置为SingleRow.
In the SQL task, under General menu, set the ResultSet property to SingleRow.
然后,在 ResultSet 菜单中,按照 select 子句的顺序添加变量,并用变量映射别名.例如:
Then, in the ResultSet menu, add the variables in the order of your select clause and map the aliases with the variables. For exemple :
SELECT 1 AS One, 2 AS Two
这篇关于SSIS-通过单个 SQL 任务设置多个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!