DTS Package Using MAX Function on Existing Table

Posted on 2006-04-27
Last Modified: 2012-05-05
I'm trying to update an existing table from our National Data Center to a local machine.  I only want to pull in the records that have a greater transaction number(Primary Key) than the records I've already pulled in.  I don't seem to be able to use the MAX function to get the largest transaction number our of my local table while I'm building the DTS Package.  Does anyone no the SQL needed to do this or is there another solution.  In other words I only want to download the new transactions because there are several thousand records in the source that I'm pulling from.

Question by:jchance
    LVL 30

    Accepted Solution

    Assuming that the transaction number is always increasing, the trick is to find the biggest tran number in the destination database, then use a sql query to only extract records with tran numbers after that.

    this is how you do it:

    1. Create a global variable (right click/package properties then go to the global variables tab)
    2. Create an execute SQL task which has this sql:

    SELECT MAX(TransactionNumber) As LastNumber FROM <YourTable>

    It needs to run that against your destination database.

    3. On that same task press the parameters button. On the output parameters tab, select output parameter type = row value, and assign your global variable that you just created in the parameter mappings

    So now test just that part - run the sql task by right click/execute step. Then check your global variable value in the right click/package properties/global variables tab. It should have picked up the last transaction number in your destination database.

    Now we need to extract data that has a transaction number after that.

    Simlpy create a data pump between your source and destination and for the source sql type:

    SELECT <field list> FROM <yourtable> WHERE transactionnumber > ?

    hit the parameters button and assign your global variable.

    Now test the whole thing. That should give you what you want.
    LVL 9

    Expert Comment

    Hi jchance,

    You don't need to use the MAX function in order to do that. You just need to pass a value of last (maximal) transaction number you stored to local machine to your DTS package and then make one select like this:

    select * from Transaction
    where TransactionID > LastMaxTransactionID

    where TransactionID is the name of your primary key column and LastMaxTransactionID is the name of parameter passed to DTS.
    Here is described how you can pass the parameter to DTS:;en-us;242391&sd=tech

    I hope this is what you need.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
    Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now