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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:57:18+00:00 2026-06-12T07:57:18+00:00

i currently have this table in SQL server: PL_ID User_ID Log_Date Out_Time In_Time Reason

  • 0

i currently have this table in SQL server:

PL_ID User_ID Log_Date Out_Time In_Time Reason Details

PL stands for people logger… then you have the user ID, the log date (date of day off), out time, in time, reason and details… there is a ASP front which allows the user to add their day off into the table which has been written by someone else… currently the users being able to do this themselves isnt an issue however, i have been given the task to add employee days off for the next YEAR…. they are recurring days off (1-3pm every monday) or (2-5 every thursday)… there must be an easier way to do this rather than just adding in one day off at a time. i have tried experimenting with dateadd but i cannot figure out the syntax to include it in the insert… one day i plan to add this to the userpage but for now i just need to get their days off into the table! sorry for being a bit vauge but i am very new to this and if i dont figure out an easy way to insert the days off, i will have to manually do it every week for the next year!

thanks in advance guys,

Tom.

  • 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-06-12T07:57:19+00:00Added an answer on June 12, 2026 at 7:57 am

    If you have a master date table, you can simply query the table for Mondays and Thrusdays for next year and can use Insert Select … Syntax.

    DECLARE @StartDate DateTime
    DECLARE @EndDate DateTime
    SET @StartDate = '1/1/2013'
    SET @EndDate = '12/31/2013'
    
    INSERT INTO DestinationTable(Date,StartTime,EndTime)
    SELECT DM.Date,
           CASE WHEN DATENAME(dw,DM.Date) = 'Thursday' THEN '1400'
                WHEN DATENAME(dw,DM.Date) = 'Monday' THEN '1300'
            END AS StartTime,
            CASE WHEN DATENAME(dw,DM.Date) = 'Thursday' THEN '1700'
                WHEN DATENAME(dw,DM.Date) = 'Monday' THEN '1500'
            END AS EndTime     
      FROM DateMaster DM
     WHERE DM.Date Between @StartDate AND @EndDate
       AND DATENAME(dw,DM.Date) IN ('Thursday','Monday')
    

    However if you do not have a master date table then we can just loop the whole year and fill in the table.

    DECLARE @StartDate DateTime
    DECLARE @EndDate DateTime
    DECLARE @DateVar DateTime
    
    SET @StartDate = '1/1/2013'
    SET @EndDate = '12/31/2013'
    SET @DateVar = @StartDate
    
    WHILE @DateVar <= @EndDate
    BEGIN 
         INSERT INTO DestinationTable(Date,StartTime,EndTime)
         SELECT @DateVar,
                CASE WHEN DATENAME(dw,@DateVar) = 'Thursday' THEN '1400'
                     WHEN DATENAME(dw,@DateVar) = 'Monday' THEN '1300'
                 END AS StartTime,
                CASE WHEN DATENAME(dw,@DateVar) = 'Thursday' THEN '1700'
                     WHEN DATENAME(dw,@DateVar) = 'Monday' THEN '1500'
                 END AS EndTime      
          WHERE DATENAME(dw,@DateVar) IN ('Thursday','Monday')
    
         SET @DateVar = DATEADD(d,1,@DateVar)
     END
    

    You can make it more efficient by jumping other days instead of just adding one day…

    CTE

    DECLARE @StartDate DateTime
    DECLARE @EndDate DateTime
    SET @StartDate = '1/1/2013'
    SET @EndDate = '12/31/2013'
    
    ;WITH DateMaster(Date)
    AS
    (
        SELECT @StartDate
         UNION ALL
        SELECT DATEADD(d,1,Date)
          FROM DateMaster
         WHERE DATEADD(d,1,Date) <= @EndDate 
        )
    
    
    INSERT INTO DestinationTable(Date,StartTime,EndTime)
    SELECT DM.Date,
           CASE WHEN DATENAME(dw,DM.Date) = 'Thursday' THEN '1400'
                WHEN DATENAME(dw,DM.Date) = 'Monday' THEN '1300'
            END AS StartTime,
            CASE WHEN DATENAME(dw,DM.Date) = 'Thursday' THEN '1700'
                WHEN DATENAME(dw,DM.Date) = 'Monday' THEN '1500'
            END AS EndTime     
      FROM DateMaster DM
     WHERE DM.Date >= @StartDate AND DM.Date <= @EndDate
       AND DATENAME(dw,DM.Date) IN ('Thursday','Monday')
    OPTION (MAXRECURSION 366) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a table structure that looks something like this(some details omitted): ColumnName
I currently have the following row in my table: course_data: user_id days <-- This
I have a table in SQL Server which looks like this: ID Code Name
I have a SQL Server 2008 table called users which stores users details. I
Hi Guys I currently have this table MEMBER **ID Position Latitude Longitute** 1 1
I have a table which is currently displayed like this: Question OptionType What is
I currently have this sql statement that I wrote and it works but it's
I have a table in SQL server which has a DATETIME field called Date_Printed.
I have a database table in Sql Server 2008 R2 which contains data stored
I have the following table in SQL Server: CREATE TABLE [dbo].[Users]( [Id] [int] IDENTITY(1,1)

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.