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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:03:54+00:00 2026-05-25T06:03:54+00:00

I want to fetch records from tData where FooTime column values within a temporary

  • 0

I want to fetch records from “tData” where FooTime column values within a temporary time ranges table “tTime”

tData table:

FooTime            Value
2010-01-01 00:15   3
2010-01-01 00:30   2
2010-01-01 00:45   4
2010-01-01 01:00   5
2010-01-01 01:15   1
2010-01-01 01:30   3
2010-01-01 01:45   4
2010-01-01 02:00   12
2010-01-01 02:15   13
2010-01-01 02:30   12
2010-01-01 02:45   14
2010-01-01 03:00   15
2010-01-01 03:15   3
2010-01-01 03:30   2
2010-01-01 03:45   3
2010-01-01 04:00   5
..........
..........
..........
2010-01-02 00:15   3
2010-01-02 00:30   2
2010-01-02 00:45   4
2010-01-02 01:00   5
2010-01-02 01:15   1
2010-01-02 01:30   3
2010-01-02 01:45   4
2010-01-02 02:00   12
2010-01-02 02:15   13
2010-01-02 02:30   12
2010-01-02 02:45   14
2010-01-02 03:00   15
2010-01-02 03:15   3
2010-01-02 03:30   2
2010-01-02 03:45   3
2010-01-02 04:00   5
..........
..........
..........


tTime table:

StartTime            EndTime
2010-01-01 02:00     2010-01-01 06:00
2010-01-02 02:00     2010-01-02 06:00
....
....
....

According to the above sample data, the following records should be returned because the time:

FooTime            Value
2010-01-01 02:00   12
2010-01-01 02:15   13
2010-01-01 02:30   12
2010-01-01 02:45   14
2010-01-01 03:00   15
2010-01-01 03:15   3
2010-01-01 03:30   2
2010-01-01 03:45   3
2010-01-01 04:00   5
...
...
2010-01-01 06:00   3


2010-01-02 02:00   12
2010-01-02 02:15   13
2010-01-02 02:30   12
2010-01-02 02:45   14
2010-01-02 03:00   15
2010-01-02 03:15   3
2010-01-02 03:30   2
2010-01-02 03:45   3
2010-01-02 04:00   5
...
...
2010-01-02 06:00   3

Please consider that the time ranges could be different for different day, for example:
tTime table:

StartTime            EndTime
2010-01-01 02:00     2010-01-01 06:00
2010-01-02 19:00     2010-01-02 24:00
....
....
....
  • 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-05-25T06:03:54+00:00Added an answer on May 25, 2026 at 6:03 am

    I’m not near my computer with MS SQL on it but this should do the trick:

    SELECT tData.*
    FROM 
        tData
        LEFT JOIN tTime
            ON CONVERT(VARCHAR(10), tTime.StartTime, 101) = CONVERT(VARCHAR(10), tData.FooTime, 101)
    WHERE
        tData.FooTime BETWEEN tTime.StartTime AND tTime.EndTime
    

    Essentially join the two tables based on the Date (without time) portion of the StartTime and FooDate, then just use a BETWEEN in the WHERE clause.

    As I said, I can’t test this on this laptop but I’d say it’d work.

    Edit: This assumes that there is only 1 day per row in the tTime table as per your example

    EDIT: Just remembered that you should be able to use BETWEEN in a JOIN criteria, so this should be better:

    SELECT tData.*
    FROM 
        tData
        INNER JOIN tTime
            ON tData.FooTime BETWEEN tTime.StartTime AND tTime.EndTime
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to fetch the unmatching records from two table in SQL, the table
I want to fetch records from a table in my sql server database in
My table has records for every minute, now I want to fetch records with
I have a table containing 10 records. I want to fetch 5th and the
I want to fetch the records from MySQL for the current year and month.
I want to fetch the top 10 records from 2 tables which have id
I want to pull data from table Province_Notifiers and also fetch all corresponding items
I'm using a loop to fetch records from a database. I want it so
I want to fetch some data from the following database table 'article'. i want
Currently I want to select the most recent value from a related table. So,

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.