Change in Salary

  • Hello all,

    Can some guide me please.  I need a script that will show me changes in a person's salary.  I can pull the current salary.  However, I want to know if a person's salary was changed 1 week from now or even month from now, I want to only see those people where the salary has changed based on a given date.

  • SQL does not keep a history of data changes. 
    unless you already have some kind of audit system in place, an audit table with a trigger, change tracking, change data capture, etc, there is no way to find what was changed.
    if your table has  the classic type 2 structure, where one personId has multiple rows, and one of them is marked as current, whether via date or a flag,  you might be able to compare current row to previous periods. Base don your description so far, i doubt that is the case.
    you could restore a database from a month ago,and do a side by side comparison to old vs new tables., but you have to add something to watch the table to capture that kind of data changes.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • ajspencer - Monday, June 5, 2017 2:03 PM

    Hello all,

    Can some guide me please.  I need a script that will show me changes in a person's salary.  I can pull the current salary.  However, I want to know if a person's salary was changed 1 week from now or even month from now, I want to only see those people where the salary has changed based on a given date.

    as a starter and to help you help us ...please read this article
    https://spaghettidba.com/2015/04/24/how-to-post-a-t-sql-question-on-a-public-forum/

    also please tell us what version of SQL you are using?

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • I'm running SQL Server 2012 Verision 11

  • ajspencer - Monday, June 5, 2017 2:19 PM

    I'm running SQL Server 2012 Verision 11

    ...great

    and in which SQL table are these salary details being stored...?  DDL Please...see the previous post on how to provide

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • With no DDL, I'll take a guess at it, but this is only a general approach.  Like J Livingston said, we'll need DDL to help with anything specific.

    Take the person's current salary and include all salary history (with dates) from the salary history table.  If you order it be effective date DESC, then you'll have the history from most recent to most distant.  From those rows, you can calculate the percentage change for each event, but the method you'll use depends on which SQL Server version you're working in.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply