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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:53:11+00:00 2026-05-16T13:53:11+00:00

I have the following tables with their columns (only the relevant columns are listed):

  • 0

I have the following tables with their columns (only the relevant columns are listed):

Entry
EntryID (int/auto-inc)
EmployeeNumber (int)
JustifyDate (datetime)
EntryDate (datetime)

Employee
EmployeeNumber (int)
CoreHourID (int)
WorkingFromHome (bit/bool)

Hour
EntryID (int)
InHour (datetime)
OutHour (datetime)

CoreHour
CoreHourID (int) – not unique
InHour (int)
OutHour (int)

EDIT: I had forgotten to mention that CoreHourID isn’t a unique field, table can look like this:

+-----------+-------+-------+----------+
|CoreHourId |InHour |OutHour|Identifier|
+-----------+-------+-------+----------+
|    2      |  9    |  12   |    1     |
|    2      |  14   |  17   |    2     |
|    3      |  7    |  11   |    3     |
|    3      |  15   |  18   |    4     |
+-----------+-------+-------+----------+

Sorry for the big layout, I really don’t know how to properly post table information.
Now here’s an attempt at explaining what I’m trying to do:

Every day, a row should be inserted in Entry and Hour for all employees who are WorkingFromHome. In the Entry table it should place the corresponding EmployeeNumber, and for JustifyDate it should add whatever day it is when the job is running. For the EntryDate field it should add that day’s date, but the time part should be the InHour from the first corresponding CoreHour row.

For the Hour table it should add the EntryID that just got inserted in the Entry table, and the InHour should be the same as the EntryDate and for the OutHour field it should add a DateTime based on the last OutHour corresponding for the employee’s CoreHourID.

I’m struggling a lot, so any help is appreciated.

PS: Any comments/questions regarding my explanation are welcome and I will gladly respond.

  • 1 1 Answer
  • 2 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-16T13:53:12+00:00Added an answer on May 16, 2026 at 1:53 pm

    The following could be encapsulated into a stored procedure that can be executed via a scheduled job. I’m not exactly sure what you meant by for JustifyDate it should add whatever day it is when the job is running.

    Declare @NewEntries Table (
                                EntryId int not null
                                , EmployeeNumber int not null
                                , JustifyDate datetime
                                , EntryDate datetime
                                )
    
    Insert [Entry]( EmployeeNumber, JustifyDate, EntryDate )
        Output Inserted.EntryId, Inserted.EmployeeNumber, Inserted.JustifyDate, Inserted.EntryDate 
            Into @NewEntries
    Select EmployeeNumber
        , CURRENT_TIMESTAMP
        , DateAdd(hh, CoreHour.InHour, DateAdd(d, 0, CURRENT_TIMESTAMP))
    From Employee
        Join CoreHour
            On CoreHour.CoreHourId = Employee.CoreHourId
    Where WorkingFromHome = 1
    
    Insert [Hour]( EntryId, InHour, OutHour )
    Select NE.EntryId, DatePart(hh, NE.EntryDate), CoreHour.OutHour
    From @NewEntries As NE
        Join Employee
            On Employee.EmployeeNumber = NE.EmployeeNumber
        Join CoreHour
            On CoreHour.CoreHourId = Employee.CoreHourId
    

    (Revised to use Output clause).

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

Sidebar

Related Questions

I have three tables, and their relevant columns are: tPerson -> PersonID tPersonStatusHistory ->
I have the following tables in a database (i'll only list the important attributes):
I'm using SQL-Server 2005 Standard. I have Users table with following columns: userID(int), userImage(varchar),
Lets say I have the following tables: TABLE: topic COLUMNs: topicId TABLE: topicPermissions COLUMNs:
I have following tables questions -> id, question_data, user_id users -> id, fname, lname
Suppose that we have following tables create table Employee( 2 EMPNO NUMBER(3), 3 ENAME
I have the following tables: users +----------+----------+----------+ | id | name | dob |
I have the following tables in my database: Products ID_PRODUCT PRODUCTNAME PRICE Customers ID_CUSTOMER
I have the following tables. I want to run a query but I think
I have the following tables. I wanted it so when I make more boxes

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.