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

  • Home
  • SEARCH
  • 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 383589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:17:51+00:00 2026-05-12T15:17:51+00:00

I’m developing a timesheet application using SQL Server as my backend and I am

  • 0

I’m developing a timesheet application using SQL Server as my backend and I am trying to figure out the best way to handle implementing relatively complex processing logic in my DB for reporting purposes.

I have a table (timesheet_entries) that is composed of the following fields:

  • entry_id

  • employee_id

  • job_id

  • job_state

  • pto_code (this signifies that the entry is Paid Time Off and is the id of what type of PTO – Vacation, Sick, etc – that it is. It is always NULL when job_id is populated, and vice versa)

  • entry_date

  • total_hours

  • ot_exempt (a boolean value that determines if the entry should be calculated in the overtime totals)

I need to create a report that can give a summary of time for each employee broken down by state. I know I can do this fairly easily by using a SUM(total_hours) and GROUP BY job_state, however I the way I need to calculate overtime has a fairly specific logic to it.

First things first I need to calculate the total number of hours for each employee for a given time period. Next I need to subtract any time that is either marked as PTO or OT Exempt to get me my total regular hours. From there I can begin counting any of the regular hours that are over 40 hours in a week into overtime. What makes it really difficult for me is that I have to be able to calculate OT by the state it was collected in by essentially tracking which entry (ordered by entry_date) pushes the user’s regular hours over 40 and then make sure I begin totaling the OT for the state the particular job is in (job_state).

For example, if an works his first 35 hours for the week in a job in NC and then spends the next 15 on job in SC, the report would have to show something like the following:

Employee Name / Job State / Reg Hours / OT Hours

Smith, John / NC / 35 / 0

Smith, John / SC / 5 / 10

And if you were to say that after he worked the 15 hours on the SC job, he began working on another job in NC he would have to begin accruing OT in NC next, since he would already be over 40 regular hours in a week. In the event that John Smith finished the week by working an additional 15 hours in NC his final report would look like:

Employee Name / Job State / Reg Hours / OT Hours

Smith, John / NC / 35 / 15

Smith, John / SC / 5 / 10

I’m pretty sure that this is something that cannot be accomplished using regular SQL. Would I have to use a UDF or something like that to accomplish this task? Considering that I can rather easily get an employee’s entries using a simple query, am I able dump the result set into the UDF to process and then output my desired result? If not, would I just have to include and execute the SQL statement within the UDF?

If anyone has any thoughts on the best way I might accomplish this task, I’d greatly appreciate it.

-Mike

  • 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-12T15:17:51+00:00Added an answer on May 12, 2026 at 3:17 pm

    Business logic belongs in the business layer. I think this is probably a little too much to be put in SQL (even if it’s possible).

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

Sidebar

Ask A Question

Stats

  • Questions 215k
  • Answers 215k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can just place the If statement inside the XML… May 12, 2026 at 10:58 pm
  • Editorial Team
    Editorial Team added an answer You will not get Hello in AsyncState. Hello will be… May 12, 2026 at 10:58 pm
  • Editorial Team
    Editorial Team added an answer Sending your output through a FileWriter is corrupting it because… May 12, 2026 at 10:58 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I have a French site that I want to parse, but am running into

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.