Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Aggregation Expand / Collapse
Author
Message
Posted Friday, January 22, 2010 3:13 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, September 25, 2014 3:40 PM
Points: 309, Visits: 729
I'm confused about how to aggregate a value in SSIS. Let's say I have a task that simply exports the employees from the DB to a flat file. I also have to keep track of MAX(EmpoyeeId) so that the next time I do this, I start with all the new employees that have been added since the last time.

How/where do I handle that aggregate? I just want a way to get that value in a variable. My first instinct was to throw an aggregate on the data flow, but I don't think that's right. That will get executed once for every record in the source. That's not what I want. I could also just drop a SQL Task on the control flow and handle it that way, but technically speaking, that's an entirely different query. It's not actually based on the Employees in the data flow.

Maybe a better way to ask the question is how do I get a MAX value from a data source into a user variable.


.
Post #852375
Posted Saturday, January 23, 2010 2:18 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:20 AM
Points: 5,180, Visits: 12,033
Use a SQL Server statement as you suggest (you can get the result of a single-valued T-SQL query into a variable (say MaxID) directly from the Execute SQL task).

Then use that returned value in your source query for the dataflow (pseudo-code: SELECT f1, f2, ... FROM EMPLOYEE WHERE ID <= User::MaxID). That way you know that things are consistent ...

...but, getting to the crux of the matter, how does knowing the MaxID now (for the current extract) help you when the job next runs?



Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
Post #852498
Posted Saturday, January 23, 2010 12:28 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, September 25, 2014 3:40 PM
Points: 309, Visits: 729
Thanks Phil, this is really not about employees at all. I just thought that might make my example a little easier to explain. This is really about exporting data to a vendor once per month. Each month, I have to make sure I don't send anything that was sent the previous month, so I keep track of the MAX record id every month and use that as a starting point the next month.

I'll give your example a try. So anything I put in the data flow gets executed once for each record. Do I understand that correctly?


.
Post #852588
Posted Saturday, January 23, 2010 12:37 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:20 AM
Points: 5,180, Visits: 12,033
Correct,


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
Post #852591
Posted Saturday, January 23, 2010 2:08 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Thursday, October 2, 2014 12:09 PM
Points: 4,358, Visits: 9,538
BSavoie (1/23/2010)
Thanks Phil, this is really not about employees at all. I just thought that might make my example a little easier to explain. This is really about exporting data to a vendor once per month. Each month, I have to make sure I don't send anything that was sent the previous month, so I keep track of the MAX record id every month and use that as a starting point the next month.

I'll give your example a try. So anything I put in the data flow gets executed once for each record. Do I understand that correctly?


I think you need to consider this a bit more. In your example, what happens if you send that data on Employee A last month, that employee is terminated this month - but, since it has already been sent you won't be sending it again?

In other words, what about updates to the system that need to be updated in the downstream systems? How are you going to identify those?

Find the column that identifies the last updated date for that entity (or creation date). Then use that date to filter for any records that have been modified since the last time you extracted the data.



Jeffrey Williams
Problems are opportunites brilliantly disguised as insurmountable obstacles.

How to post questions to get better answers faster
Managing Transaction Logs
Post #852615
Posted Saturday, January 23, 2010 5:29 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, September 25, 2014 3:40 PM
Points: 309, Visits: 729
Thanks Jeffery. I was just using Employees as an example to make things easier. Actually what I'm really sending is all the Guest Reservations that have stayed at a hotel over the last month. So, it's not really a volitle entity like an employee. That was probably a bad example. Thanks for the feedback!

.
Post #852650
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse