2

我有一个必须运行总计的场景,我可以通过纯 T-SQL 或脚本任务来实现这一点。但我想避免手动编码,并使用 ETL 工具功能。是否可能以及如何。

我有表余额

SELECT '00000001' AS [AccountNo], CONVERT(date,'20080828') AS [Date],10 AS [DailyMovement]
INTO   balances
UNION  ALL
SELECT '00000001' AS [AccountNo], CONVERT(date,'20080829') AS [Date],5 AS [DailyMovement]
UNION  ALL
SELECT '00000001' AS [AccountNo], CONVERT(date,'20080830') AS [Date],7 AS [DailyMovement]
UNION  ALL
SELECT '00000002' AS [AccountNo], CONVERT(date,'20080828') AS [Date],8 AS [DailyMovement]
UNION  ALL
SELECT '00000002' AS [AccountNo], CONVERT(date,'20080829') AS [Date],6 AS [DailyMovement]

我得到了这样的结果。

SELECT b1.[AccountNo]
,      b1.[Date]
,      b1.[DailyMovement]
,      SUM(b2.[DailyMovement]) AS [RunningTotal]
FROM   balances b1
INNER  JOIN balances b2 ON  b1.[AccountNo] = b2.[AccountNo]
                           AND b1.[Date] >= b2.[Date]
GROUP  BY b1.[AccountNo],b1.[Date],b1.[DailyMovement]; 

想在 SSIS 中执行此操作而无需手动编码

4

2 回答 2

3

您是否尝试添加查询

SELECT b1.[AccountNo]
,      b1.[Date]
,      b1.[DailyMovement]
,      SUM(b2.[DailyMovement]) AS [RunningTotal]
FROM   balances b1
INNER  JOIN balances b2 ON  b1.[AccountNo] = b2.[AccountNo]
                           AND b1.[Date] >= b2.[Date]
GROUP  BY b1.[AccountNo],b1.[Date],b1.[DailyMovement]; 

到 oledbsource 以将其用作 Source,然后直接将其指向 oledbdestination?

于 2012-05-29T13:39:23.897 回答
1

没有。不是没有手工编码的东西。我发现运行总计的最佳选择是 Jeff Moden 在SQLServerCentral的这篇文章

于 2012-05-29T19:47:20.013 回答