Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Recalculate "Amount" Column Expand / Collapse
Author
Message
Posted Wednesday, September 4, 2013 10:01 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, April 18, 2014 3:01 PM
Points: 38, Visits: 176
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');
Post #1491619
Posted Thursday, September 5, 2013 1:31 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:41 AM
Points: 6,789, Visits: 14,000
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
Exploring Recursive CTEs by Example Dwain Camps
Post #1491649
Posted Thursday, September 5, 2013 9:06 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 11:50 AM
Points: 13,082, Visits: 12,547
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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1491837
Posted Thursday, September 5, 2013 9:23 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:41 AM
Points: 6,789, Visits: 14,000
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
Exploring Recursive CTEs by Example Dwain Camps
Post #1491857
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse