Recalculate "Amount" Column

  • Our Salaried Employees have to log in their time by department and by type of Earnings (Regular, Holiday, Sick, etc). We are on a semi monthly pay period - therefore the number of hours worked each pay period vary - but the amount of pay is exactly the same each pay period.

    On each employee's pay record there are 2 fields Pay Per Period and Equivalent Hourly Rate.

    When the payroll is calculated the, the payroll application calculates the Amount column based on a prorated hourly rate - so the total amount of payroll is exactly the same each pay period.

    The business requirements are such that if an Employee has Vacation on their timecard - the Amount for the Vacation Hours should be calculated based on the "Equivalent Hourly Rate" and the balance on a prorated rate. The total of Vacation and Regular/Sick, etc. should equal the employee's pay for pay period - accounting also for any rounding differences. Below is a sample table - the amount column needs to be recalculated whenever there is VACATION used by Employee. For the Vacation Row the Amount should be the Hours times the Equivalent Hourly Rate and the other earnings items should be based on a prorated rate. I only need to Update the values of the Amount column.

    Thanks

    CREATE TABLE Payroll

    (

    EmpID int,

    EarningCode varchar(255),

    PayPerPeriod varchar (255),

    EQHourlyRate varchar(255),

    HoursWorked varchar(255),

    Amount varchar(255),

    Dept varchar (255)

    );

    Insert Into Payroll Values ( '100','Regular','2000','23.0769','52','1000','SALES');

    Insert Into Payroll Values ( '100','Holiday','2000','23.0769','12','230.77','SALES');

    Insert Into Payroll Values ( '100','Sick','2000','23.0769','12','230.77','SALES');

    Insert Into Payroll Values ( '100','Jury Duty','2000','23.0769','8','153.85','SALES');

    Insert Into Payroll Values ( '100','Vacation','2000','23.0769','10','192.31','SALES');

    Insert Into Payroll Values ( '100','Vacation','2000','23.0769','10','192.3','MKT');

    Insert Into Payroll Values ( '200','Regular','2000','23.0769','104','2000','ADMIN');

    Insert Into Payroll Values ( '300','Regular','2000','23.0769','88','1692.31','ACCT');

    Insert Into Payroll Values ( '300','Holiday','2000','23.0769','8','153.85','ACCT');

    Insert Into Payroll Values ( '300','Sick','2000','23.0769','8','153.84','ACCT');

    Insert Into Payroll Values ( '400','Regular','2000','23.0769','40','769.23','HR');

    Insert Into Payroll Values ( '400','Regular','2000','23.0769','40','769.23','ADMIN');

    Insert Into Payroll Values ( '400','Vacation','2000','23.0769','24','461.54','HR');

    Insert Into Payroll Values ( '500','Regular','2000','23.0769','66','1269.23','ACCT');

    Insert Into Payroll Values ( '500','Holiday','2000','23.0769','8','153.85','ACCT');

    Insert Into Payroll Values ( '500','Vacation','2000','23.0769','5','96.15','ACCT');

    Insert Into Payroll Values ( '500','Vacation','2000','23.0769','10','192.31','ADMIN');

    Insert Into Payroll Values ( '500','Vacation','2000','23.0769','15','288.46','HR');

  • Almost clear enough to make a stab at it...could you post the expected result set, or, alternatively, add an extra column say 'NewAmount' to your sample data which contains the values you are expecting to see in the 'Amount' column? Cheers.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • This thread has now moved to a new one...not sure why.

    http://www.sqlservercentral.com/Forums/Topic1491832-1292-1.aspx

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (9/5/2013)


    This thread has now moved to a new one...not sure why.

    http://www.sqlservercentral.com/Forums/Topic1491832-1292-1.aspx

    Thanks Sean - I'll post the same question there. Cheers.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

Viewing 4 posts - 1 through 3 (of 3 total)

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