How to use TSQL in the Conditional Split Data Transfer in SSIS

I have a SSIS Project where I want to "pull" data from a file that only keeps the row with the Max Date. So if Salesman 111 has 3 orders dated 01/01/2011, 02/02/2013 and 03/03/2013. I want to keep the row with Salesman 111 and date 03/03/2013. The other rows 111 01/01/2011 and 111 02/02/2012 will not be used.

The SQL Code for this being:
SELECT Salesman, MAX([Date]) AS "Max Date"  
FROM tblorders  
GROUP BY Salesman

So in my SSIS package I was hoping to use the Conditional Split and that is where I stumble. I see all columns and functions that can be used, but not where I can script my code.

Please advise.
SeTechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vikas GargBusiness Intelligence DeveloperCommented:
Hello,

The shortest solution for this would be extract all the data to the sql table and then write the below query to remove the unwanted records.

You can use execute sql task after the DFT and write the below query

;WITH CTE AS
(
SELECT Salesman, [Date] , ROW_NUMBER()over(partition by Salesman order by Salesman, [Date] desc) RN
FROM tblorders  
)

DELETE FROM CTE WHERE RN > 1

Open in new window

0
SeTechAuthor Commented:
Looking to do this in the SSIS application, I understand your SQL and the SQL I supplied will work as well. How in the Conditional transformation task can this be done???
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Sounds like a Slowly Changing Dimension (SCD) destination as far as canned SSIS components.
Pragmatic Works' Task Factory ($1,500 ish) has an Upsert Destination component which is easier to use.   I've used it on multiple projects with success.

Pretty sure CozyRoc has an equivalent component but I haven't worked with it before.

If a 'staging' table is in this picture, where rows are loaded first into the staging table and then into a production table, then I'd go with Vikas' methodology, as it'll be much easier to implement.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.