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

Ask A Question

Stats

  • Questions 97k
  • Answers 97k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You're doing something completely wrong. parentViewController is declared as a… May 11, 2026 at 7:28 pm
  • Editorial Team
    Editorial Team added an answer Found my solution... using the Office Open XML SDK and… May 11, 2026 at 7:28 pm
  • Editorial Team
    Editorial Team added an answer $("#parentDiv div")[0] // returns a regular DOM object, NOT jquery… May 11, 2026 at 7:28 pm

Related Questions

We've run into an interesting situation that needs solving, and my searches have turned
I use application managed security for an Intranet web application. I have the next
Just a very general question, that not only applies to this example. Let's say
The problem I have is this: I have a table (just an example) with
I have a distributed Java application running on 5 application servers. The servers all

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.