Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

How to calculative cumulative totals within a script component

$
0
0
How to calculative cumulative totals within a script component.

Here is a problem I am trying to work through.

1. An OLE DB Source Data Flow Source uses the following SQL:

SELECT Customer_ID, Date_Key, Dollars
ORDER BY Customer_ID, Date_Key;

The following would be a sample result set:

Customer_ID, Date_Key, Dollars
A, 20130527, 1000
A, 20130528, 1000
A, 20130529, 1000
A, 20130530, 1000
A, 20130531, 1000
B, 20130527, 1000
B, 20130528, 1000
B, 20130529, 1000
B, 20130530, 1000
B, 20130531, 1000

2. Then, using a Script Component Data Flow Transformation, I would like to do the following:

For each record, calculate the cumulative dollars starting on the first date_key for a customer.

So the output of the script task would look something like this:

Customer_ID, Date_Key, Dollars, Cumulative_Dollars
A, 20130527, 1000, 1000
A, 20130528, 1000, 2000
A, 20130529, 1000, 3000
A, 20130530, 1000, 4000
A, 20130531, 1000, 5000
B, 20130527, 1000, 1000
B, 20130528, 1000, 2000
B, 20130529, 1000, 3000
B, 20130530, 1000, 4000

I have no idea how to do step #2 in a Script Component. Any ideas?  

Thanks!!!!!!!

Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>