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 7612095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:49:28+00:00 2026-05-31T01:49:28+00:00

I have a view that I want to use to generate a payroll report.

  • 0

I have a view that I want to use to generate a payroll report.
I want it such that it selects/gets the last 3 months of monthly processed data.
E.g. If today is 15th May 2012 and payroll for May has not been done, I want to get the results for April, March and February only.

My query:

SELECT  dbo.[@EIM_PROCESS_DATA].U_Tax_year, dbo.[@EIM_PROCESS_DATA].U_Employee_ID, SUM(dbo.[@EIM_PROCESS_DATA].U_Amount) AS PAYE, 
              dbo.OADM.CompnyName, dbo.OADM.CompnyAddr, dbo.OADM.TaxIdNum, dbo.OHEM.lastName + ', ' + ISNULL(dbo.OHEM.middleName, '') 
              + ' ' + ISNULL(dbo.OHEM.firstName, '') AS EmployeeName, dbo.OHEM.govID, dbo.[@EIM_PROCESS_DATA].U_Process_month
FROM     dbo.[@EIM_PROCESS_DATA] INNER JOIN
               dbo.OHEM ON dbo.[@EIM_PROCESS_DATA].U_Employee_ID = dbo.OHEM.empID CROSS JOIN
               dbo.OADM
WHERE   (dbo.[@EIM_PROCESS_DATA].U_PD_code = 'SYS033')
GROUP BY dbo.[@EIM_PROCESS_DATA].U_Tax_year, dbo.[@EIM_PROCESS_DATA].U_Employee_ID, dbo.OADM.CompnyName, dbo.OADM.CompnyAddr, dbo.OADM.TaxIdNum, 
                      dbo.OHEM.lastName, dbo.OHEM.firstName, dbo.OHEM.middleName, dbo.OHEM.govID, dbo.[@EIM_PROCESS_DATA].U_Process_month

The field U_Process_Month stores the name of the months of the year (varchar). Any help?

  • 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-31T01:49:29+00:00Added an answer on May 31, 2026 at 1:49 am

    Here is one option if you want to turn a month name into a datetime:

    declare @Month varchar(10) = 'DEC'
    declare @Year varchar(4) = '2012'
    
    SELECT CAST(@Month ' ' + @Year AS DATETIME) AS KeyDate
    

    Replace the @Month and @Year variables with your field names, and you have the first step 😉

    For selecting only the last three months, try the HAVING clause, together with a variable @MaxKeydate that indicates the last processed month:

    SELECT (...) FROM bla
    HAVING KeyDate > DATEADD(month, -3, @MaxKeyDate)
    

    You need to see yourself, if you can determine the value for @MaxKeyDate with a simple

    SELECT MAX(CAST(@Month ' ' + @Year AS DATETIME)) FROM bla
    

    or if it is more complicated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view in SQL Server 2008 that I want to use for
I have such view that handles user registration. After creating new user i want
I have a view that I want to be converted into JSON. What is
I have an index view that I want to update automatically as the user
I have a partial view that I want to basically take care of itself
I have a MS SQL view that I want to make available as a
In my application I want to have one view that holds 2 partial views.
I have a view that has a tooltip attribute. I want to set that
I have a view controller that houses a UIWebView. I want to display an
i have a scroll view in my application and i want that when the

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.