我有一个必须运行总计的场景,我可以通过纯 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 中执行此操作而无需手动编码