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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:58:31+00:00 2026-05-11T15:58:31+00:00

I have a situation which I have solved in two different ways, but was

  • 0

I have a situation which I have solved in two different ways, but was wondering what people thought about the options, and if they have any other alternatives…

The system is processing ‘intervals’ of data.

  • All the data is allocated to an ‘interval’
  • The interval is represented by an ‘interval_start’ DATETIME in the Fact table
  • A Dimenstion table holds the duration of the ‘interval’ (can be different for different entities)
  • Also in the Dimension table is a ‘mode’ flag

The following rules are needed in a SQL Query…

Mode 0
If a record entry is in the fact table, it can be processed.
(No restrictions.)

Mode 1
A record is only valid for processing if the ‘interval_start’ is in the past. (Intervals of time that have already begun, but not necessarily finished.)

Mode 2
A record is only valid for processing if the whole ‘interval’ is in the past. (Intervals of time that have finished.)

The first WHERE clause created for this was as follows…

WHERE     getDate() >=         CASE [table].mode             WHEN 0 THEN 0             WHEN 1 THEN [log].interval_start             WHEN 2 THEN [log].interval_start + [table].interval_period             ELSE        NULL         END 

There was a concern that this would obsfuscate indexes from optimising the clause. The alternative was to use multiple AND/OR conditions.

WHERE    ([table].mode = 0 AND getDate() >= 0) OR ([table].mode = 1 AND getDate() >= [log].interval_start) OR ([table].mode = 2 AND getDate() >= [log].interval_start + [table].interval_period) 

Obviously, which will perform best will depend on the data and indexes, etc. But does anyone have any opion or alternative for what I’m currently describing as ‘conditional conditions’? 🙂

Cheers, Mat.

  • 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. 2026-05-11T15:58:31+00:00Added an answer on May 11, 2026 at 3:58 pm

    Another option would be to run three separate queries and UNION them together. Depending on your index and table structure, that might lead to more efficient SQL than OR-ing together the clauses in the WHERE clause or using CASE statements, although it would purely be gaming the optimizer.

    I’d test all three approaches and pick the one that works best for you.

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

Sidebar

Related Questions

I have come across a situation (which I think is weird but is possibly
I have situation in which I read a record from a database. And if
I have a situation in which a managed DLL calls some unmanaged DLL. I
I have a situation in which I need to convert a text data into
I have a situation in which user can single tap a control, which show
I have a situation in which the ideal relationship, I believe, would involve Value
I have a situation in which I am putting the UITableView in editing mode,
I have an odd situation in which I need to modify the position of
I have a situation where I need to retrieve data from a query which
I have following situation - Have a MongoService class, which reads host, port, database

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.