Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Recalculate "Amount" Column


Recalculate "Amount" Column

Author
Message
nfpacct
nfpacct
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 Visits: 194
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');
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)

Group: General Forum Members
Points: 8949 Visits: 19009
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
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16529 Visits: 16992
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)
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)

Group: General Forum Members
Points: 8949 Visits: 19009
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search