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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:51:17+00:00 2026-06-09T12:51:17+00:00

I have a program that autoruns with Windows scheduler. This program runs a stored

  • 0

I have a program that autoruns with Windows scheduler. This program runs a stored procedure which uses Yesterdays date, to run a query against our database to pull results from the previous day. This query EXCLUDES a specific time period throughout the day as we do not care about those results. However, we have different hours on Sunday, and would like to change the query for Sunday… Is there a way to query differently if it’s a “Sunday”? Below is my stored procedure:

CREATE PROCEDURE [dbo].[sp_Open_Close_Report_1] AS
declare   @dtNow         datetime ,   @dtToday       datetime ,   @dtFrom        datetime ,   @dtThru        datetime ,   @dtExcludeFrom datetime ,   @dtExcludeThru datetime, @dtExcludeEOD datetime 
set @dtNow         = getdate() 
set @dtToday       = convert(datetime,convert(varchar,@dtNow,112),112) 
set @dtFrom        = dateadd(day,-1,@dtToday) -- start-of-day yesterday 
set @dtThru        = dateadd(ms,-3,@dtToday)  -- end-of-day yesterday (e.g., 2012-06-17 23:59:59.997) 
set @dtExcludeFrom = convert(datetime, convert(char(10),@dtFrom,120) + ' 05:30:00.000' , 120 ) 
set @dtExcludeThru = convert(datetime, convert(char(10),@dtFrom,120) + ' 06:15:00.000' , 120 ) 
set @dtExcludeEOD = convert(datetime, convert(char(10),@dtFrom,120) + ' 08:00:00.000' , 120 ) 


SELECT Store_Id , DM_Corp_Received_Date, Register_Transaction_Type 
FROM Register_Till_Count_Tb 
WHERE (Register_Transaction_Type    =  'SOD' and store_ID = '12345'
AND DM_Corp_Received_date     between @dtFrom        
and @dtThru   
AND DM_Corp_Received_date not between @dtExcludeFrom 
and @dtExcludeThru) or (Register_Transaction_Type = 'EOD' and Store_ID='12345'
AND DM_Corp_Received_date Between @dtFrom and @dtThru)

On Sunday the @DTExclude From will be 6:30 and @dtexcludeThru will be 7:15

  • 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-09T12:51:18+00:00Added an answer on June 9, 2026 at 12:51 pm

    Lets do more of the maths keeping everything as datetimes (or ints) rather than mucking about with strings:

    declare   @dtNow         datetime ,   @dtToday       datetime ,   @dtFrom        datetime ,   @dtThru        datetime ,   @dtExcludeFrom datetime ,   @dtExcludeThru datetime, @dtExcludeEOD datetime 
    set @dtNow         = getdate() 
    set @dtToday       = DATEADD(day,DATEDIFF(day,0,@dtNow),0)
    set @dtFrom        = dateadd(day,-1,@dtToday)
    
    declare @Sunday int
    set @Sunday = CASE WHEN DATEPART(weekday,@dtFrom) = DATEPART(weekday,'20120805') THEN 1 ELSE 0 END
    set @dtExcludeFrom = DATEADD(minute,330 + @Sunday * 60,@dtFrom)
    set @dtExcludeThru = DATEADD(minute,375 + @Sunday * 60,@dtFrom)
    set @dtExcludeEOD = DATEADD(minute,480,@dtFrom)
    

    And, in your query, rather than having:

    column between @dtFrom and @dtThru
    

    use:

    column >= @dtFrom and column < @dtToday
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a VB.Net program that auto runs with windows scheduler. The program runs
I am making a program that auto-runs using windows scheduler. What I'd like to
I have a program that auto launches with Windows via scheduler. What it does
I have program that requires Python 3, but I develop Django and it uses
I have program that runs fast enough. I want to see the number of
I have a program that creates UIViewControllers in a UISplitView depending upon which row
I have program that I want to test on clean Windows installation. For now
I have program that runs for long periods of time and I'd like to
I have program, that has structure defined like this: struct foo { int magic;
I have program output that looks like this (tab delim): $ ./mycode somefile 0000000000000000000000000000000000

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.