【问题标题】:How to map multiple row results to different variables in SSIS Execute SQL Task?如何将多行结果映射到 SSIS 执行 SQL 任务中的不同变量?
【发布时间】:2020-05-13 13:57:29
【问题描述】:

我需要在同一个 SSIS 包中用不同的变量映射 1 列从多个 SQL 查询的结果行。

例如, 我的查询的输出是:

Category, Count  
A, 16  
B, 23  
C, 41  
D, 72  
E, 32

我希望将 Count 的值分配给我的包中的 5 个不同的变量。

VariableA = 16
VariableB = 23
and so on.

我遇到了一个对象的多个结果集,然后使用 ForEach 循环容器从中读取。但是,它将不同的结果存储在同一个变量中。 我想将这些变量用作数据流任务中多行采样转换的数字,因此我需要它们作为单独的变量。 有没有办法解决这个问题并在 SSIS 中获得上述结果?

【问题讨论】:

  • 将您的 SQL 查询转为一行

标签: variables ssis foreach-loop-container execute-sql-task


【解决方案1】:

就像我上面评论的那样。您可以转置查询结果...

;with YourQuery as
( 
select *
from (values('A',16),('B',23),('C',41),('D',72),('E',32)) as a(Cat,Ct)
)

select A=Max(case when cat='A' then Ct else 0 end)
    ,B=Max(case when cat='B' then Ct else 0 end)
    ,C=Max(case when cat='C' then Ct else 0 end)
    ,D=Max(case when cat='D' then Ct else 0 end)
    ,E=Max(case when cat='E' then Ct else 0 end)
from YourQuery

结果:

A   B   C   D   E
16  23  41  72  32

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-27
    相关资源
    最近更新 更多