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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:46:32+00:00 2026-06-11T05:46:32+00:00

I’m forced to work with a table with the following structure (ScheduledEmails) and am

  • 0

I’m forced to work with a table with the following structure (ScheduledEmails) and am looking to find the most efficient way to deal with multiple variables being set to 1 (true)

The script below will only return the correct value if only one is selected.

Could anybody recommend a way to modify the bottom query to accomodate multiple conditions.

e.g. where @IsMonday and @IsTuesday is true etc.?

I have tried multiple combinations of AND/OR but none seem to yield the desired result.

DECLARE @IsMonday bit
DECLARE @IsTuesday bit
DECLARE @IsWednesday bit
DECLARE @IsThursday bit
DECLARE @IsFriday bit
DECLARE @IsSaturday bit
DECLARE @IsSunday bit
DECLARE @Is0000 bit
DECLARE @Is0100 bit
DECLARE @Is0200 bit
DECLARE @Is0300 bit
DECLARE @Is0400 bit
DECLARE @Is0500 bit
DECLARE @Is0600 bit
DECLARE @Is0700 bit
DECLARE @Is0800 bit
DECLARE @Is0900 bit
DECLARE @Is1000 bit
DECLARE @Is1100 bit
DECLARE @Is1200 bit
DECLARE @Is1300 bit
DECLARE @Is1400 bit
DECLARE @Is1500 bit
DECLARE @Is1600 bit
DECLARE @Is1700 bit
DECLARE @Is1800 bit
DECLARE @Is1900 bit
DECLARE @Is2000 bit
DECLARE @Is2100 bit
DECLARE @Is2200 bit
DECLARE @Is2300 bit

DECLARE @dayOfWeek VARCHAR(20)
DECLARE @hourOfDay int

SET @dayOfWeek = datename(dw,GETDATE()) -- Monday to Sunday
SET @hourOfDay = datepart(hh, GETDATE()) -- Single digit 0 - 23

SET @IsMonday = CASE WHEN @dayOfWeek = 'Monday' THEN 1 ELSE 0 END
SET @IsTuesday = CASE WHEN @dayOfWeek = 'Tuesday' THEN 1 ELSE 0 END
SET @IsWednesday = CASE WHEN @dayOfWeek = 'Wednesday' THEN 1 ELSE 0 END
SET @IsThursday = CASE WHEN @dayOfWeek = 'Thursday' THEN 1 ELSE 0 END
SET @IsFriday = CASE WHEN @dayOfWeek = 'Friday' THEN 1 ELSE 0 END
SET @IsSaturday = CASE WHEN @dayOfWeek = 'Saturday' THEN 1 ELSE 0 END
SET @IsSunday = CASE WHEN @dayOfWeek = 'Sunday' THEN 1 ELSE 0 END
SET @Is0000 = CASE WHEN @hourOfDay = 0 THEN 1 ELSE 0 END
SET @Is0100 = CASE WHEN @hourOfDay = 1 THEN 1 ELSE 0 END
SET @Is0200 = CASE WHEN @hourOfDay = 2 THEN 1 ELSE 0 END
SET @Is0300 = CASE WHEN @hourOfDay = 3 THEN 1 ELSE 0 END
SET @Is0400 = CASE WHEN @hourOfDay = 4 THEN 1 ELSE 0 END
SET @Is0500 = CASE WHEN @hourOfDay = 5 THEN 1 ELSE 0 END
SET @Is0600 = CASE WHEN @hourOfDay = 6 THEN 1 ELSE 0 END
SET @Is0700 = CASE WHEN @hourOfDay = 7 THEN 1 ELSE 0 END
SET @Is0800 = CASE WHEN @hourOfDay = 8 THEN 1 ELSE 0 END
SET @Is0900 = CASE WHEN @hourOfDay = 9 THEN 1 ELSE 0 END
SET @Is1000 = CASE WHEN @hourOfDay = 10 THEN 1 ELSE 0 END
SET @Is1100 = CASE WHEN @hourOfDay = 11 THEN 1 ELSE 0 END
SET @Is1200 = CASE WHEN @hourOfDay = 12 THEN 1 ELSE 0 END
SET @Is1300 = CASE WHEN @hourOfDay = 13 THEN 1 ELSE 0 END
SET @Is1400 = CASE WHEN @hourOfDay = 14 THEN 1 ELSE 0 END
SET @Is1500 = CASE WHEN @hourOfDay = 15 THEN 1 ELSE 0 END
SET @Is1600 = CASE WHEN @hourOfDay = 16 THEN 1 ELSE 0 END
SET @Is1700 = CASE WHEN @hourOfDay = 17 THEN 1 ELSE 0 END
SET @Is1800 = CASE WHEN @hourOfDay = 18 THEN 1 ELSE 0 END
SET @Is1900 = CASE WHEN @hourOfDay = 19 THEN 1 ELSE 0 END
SET @Is2000 = CASE WHEN @hourOfDay = 20 THEN 1 ELSE 0 END
SET @Is2100 = CASE WHEN @hourOfDay = 21 THEN 1 ELSE 0 END
SET @Is2200 = CASE WHEN @hourOfDay = 22 THEN 1 ELSE 0 END
SET @Is2300 = CASE WHEN @hourOfDay = 23 THEN 1 ELSE 0 END

INSERT INTO ScheduledEmailQueue (ScheduledEmailId, Created)
SELECT Id, GETDATE() FROM ScheduledEmails WHERE 
(SendMonday = @IsMonday AND
SendTuesday = @IsTuesday AND
SendWednesday = @IsWednesday AND
SendThursday= @IsThursday AND
SendFriday = @IsFriday AND
SendSaturday = @IsSaturday AND
SendSunday = @IsSunday AND
Send0000 = @Is0000 AND
Send0100 = @Is0100 AND 
Send0200 = @Is0200 AND 
Send0300 = @Is0300 AND 
Send0400 = @Is0400 AND 
Send0500 = @Is0500 AND 
Send0600 = @Is0600 AND 
Send0700 = @Is0700 AND 
Send0800 = @Is0800 AND 
Send0900 = @Is0900 AND 
Send1000 = @Is1000 AND 
Send1100 = @Is1100 AND 
Send1200 = @Is1200 AND 
Send1300 = @Is1300 AND 
Send1400 = @Is1400 AND 
Send1500 = @Is1500 AND 
Send1600 = @Is1600 AND 
Send1700 = @Is1700 AND 
Send1800 = @Is1800 AND 
Send1900 = @Is1900 AND 
Send2000 = @Is2000 AND 
Send2100 = @Is2100 AND 
Send2200 = @Is2200 AND 
Send2300 = @Is2300)

SELECT Id, GETDATE() FROM ScheduledEmails WHERE 
SendMonday= @IsMonday AND
SendTuesday = @IsTuesday AND
SendWednesday = @IsWednesday AND
SendThursday= @IsThursday AND
SendFriday = @IsFriday AND
SendSaturday = @IsSaturday AND
SendSunday = @IsSunday AND
Send0000 = @Is0000 AND
Send0100 = @Is0100 AND 
Send0200 = @Is0200 AND 
Send0300 = @Is0300 AND 
Send0400 = @Is0400 AND 
Send0500 = @Is0500 AND 
Send0600 = @Is0600 AND 
Send0700 = @Is0700 AND 
Send0800 = @Is0800 AND 
Send0900 = @Is0900 AND 
Send1000 = @Is1000 AND 
Send1100 = @Is1100 AND 
Send1200 = @Is1200 AND 
Send1300 = @Is1300 AND 
Send1400 = @Is1400 AND 
Send1500 = @Is1500 AND 
Send1600 = @Is1600 AND 
Send1700 = @Is1700 AND 
Send1800 = @Is1800 AND 
Send1900 = @Is1900 AND 
Send2000 = @Is2000 AND 
Send2100 = @Is2100 AND 
Send2200 = @Is2200 AND 
Send2300 = @Is2300
  • 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-11T05:46:34+00:00Added an answer on June 11, 2026 at 5:46 am

    If I have understood your requirement correctly, you just want to select the records for current day of week and hour from ScheduledEmails table, and insert them into ScheduledEmailQueue table. If that is indeed the case, you can create a dynamic sql query and execute it. If I have understood your requirement incorrectly, then I apologise in advance 🙂

    DECLARE @dayOfWeek VARCHAR(20)
    DECLARE @hourOfDay INT
    DECLARE @hourOfDayColumnName VARCHAR(20)
    DECLARE @dayOfWeekColumnName VARCHAR(20)
    DECLARE @sql VARCHAR(MAX)
    
    SET @dayOfWeek = datename(dw,GETDATE()) -- Monday to Sunday
    SET @hourOfDay = datepart(hh, GETDATE()) -- Single digit 0 - 23
    SET @hourOfDayColumnName = 'Send' + CASE WHEN LEN(@hourOfDay) = 1 THEN '0' + CONVERT(VARCHAR, @hourOfDay) ELSE CONVERT(VARCHAR, @hourOfDay) END + '00'
    SET @dayOfWeekColumnName = 'Send' + @dayOfWeek
    SET @sql = 'INSERT INTO ScheduledEmailQueue (ScheduledEmailId, Created)
    SELECT Id, GETDATE() FROM ScheduledEmails WHERE ' + @dayOfWeekColumnName + ' = 1 AND ' + @hourOfDayColumnName + ' = 1'
    
    PRINT @hourOfDayColumnName
    PRINT @dayOfWeekColumnName
    PRINT @sql
    EXEC (@sql)
    

    Sorry, I misread your question, but I am still not clear about your requirements. If you use DayOfWeek and Hour, they will always return you singular values (e.g. Monday and 22). If you want to select values based on multiple criteria, then you will have to do a simple hardcoded query like:

    SELECT Id, GETDATE() FROM ScheduledEmails WHERE 
    SendMonday= 1 AND
    SendTuesday = 1 AND
    Send0000 = 1 AND
    Send0100 = 1
    

    If you do not know the values for required days and hours beforehand, then you can just pass them as parameters to a stored proc and use them for filtering.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.