Handling increments and decrements in SQL

hello All,

I have time records stored in this Master Table and will be importing time records to the timesheet app every 5 minutes from the Master table. I will need to get only 5 the differences and only new data from the master data table. I have  unique fields and two fields that will change everytime which is the minutes worked and the Paycode.

For example if an employee enters 300 minutes and later changes to 200 minutes I want the code send -100 or when an employee enters 100 minutes and later changes it to 400 want it to send +300 minutes to the app.

I am still brainstoming, even though you might not provide the actual code but I just need the pseudocode. I have no where to start thats why I did not provide any sample code.

Please assist and dont mistake me not having anywhere to start as laziness.

thank you.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
You need a complete copy of the prior absolute data for getting differences.  Match both, subtract the values, and remove anything with 0 values only. Then replace the copy with the actual data for the next go.
Vitor MontalvãoMSSQL Senior EngineerCommented:
You can achieve that with an TRIGGER FOR UPDATE where you'll have the old value in a table called deleted and the new value in a table called inserted. Example:
CREATE TRIGGER trgDifferences ON TableName
    SELECT (inserted.ColumnName - deleted.ColumnName) AS difference
    FROM inserted
    INNER JOIN deleted ON inserted.PKcolumn = deleted.PKcolumn

Open in new window

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

From novice to tech pro — start learning today.