Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 667881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:58:39+00:00 2026-05-13T23:58:39+00:00

I have a sql table of payroll data that has wage rates and effective

  • 0

I have a sql table of payroll data that has wage rates and effective dates associated with those wage rates, as well as hours worked on various dates. It looks somewhat like this:

EMPID  DateWorked  Hours  WageRate  EffectiveDate

1      1/1/2010     10     7.00      6/1/2009
1      1/1/2010     10     7.25      6/10/2009
1      1/1/2010     10     8.00      2/1/2010
1      1/10/2010 ...
2      1/1/2010  ...

…

And so on. Basically, the data has been combined in such a way that for every day worked, all of the employee’s wage history is joined together, and I want to grab the wage rate associated with the LATEST effective date that is not later than the date worked. So in the example above, the rate of 7.25 that become effective on 6/10/2009 is what I want.

What kind of query can I put together for this? I can use MAX(EffectiveDate) alongwith a criteria based on being before the work date, but that only gives me the latest date itself, I want the associated wage. I am using Sql Server for this.

Alternatively, I have the original tables that were used to create this data. One of them contains the dates worked, and the hours as well as EMPID, the other contains the list of wage rates and effective dates. Is there a way to join these instead that would correctly apply the right wage rate for each work day?

I was thinking that I’d want to group by EMPID and then DateWorked, and do something from there. I want to get a result that gives me the wage rate that actually is the latest effective rate for each date worked

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:58:40+00:00Added an answer on May 13, 2026 at 11:58 pm
    select p.*
    from (
        select EMPID, DateWorked, Max(EffectiveDate) as MaxEffectiveDate
        from Payroll
        where EffectiveDate <= DateWorked
        group by EMPID, DateWorked
    ) pm
    inner join Payroll p on pm.EMPID = p.EMPID and pm.DateWorked = p.DateWorked and pm.MaxEffectiveDate = p.EffectiveDate
    

    Output:

    EMPID       DateWorked              Hours       WageRate                                EffectiveDate
    ----------- ----------------------- ----------- --------------------------------------- -----------------------
    1           2010-01-01 00:00:00.000 10          7.25                                    2009-06-10 00:00:00.000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have SQL table that has a varchar(8) column that occasionally has binary data
I have an sql table of PlayerTrial that holds, well, player trials. ---PlayerTrials Basic
I have a SQL table which has a number of fields ID | Value
I have a sql table which have the following data, Id City Country ---
I have a T-SQL table variable (not a table) which has an auto incrementing
I have a MS SQL table that I don't have any control over and
Does anyone have a technique for generating SQL table create (and data insert) commands
I have an SQL table called trainings that looks like this: +-----+-----------+--------+------------+------------+------------+-------+ | Id
I have a sql table, it has many coloumns. For Instance; The Table :
I have a SQL table with news stories and Unix timestamps. I'd like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.