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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:13:37+00:00 2026-05-16T07:13:37+00:00

I have a records like this: start, end , total 830 , 1300, 5

  • 0

I have a records like this:

start, end , total  
 830 , 1300,   5
 1400, 1430,   2

that I’d like to expand to:

instance , total  
  830    ,   5
  831    ,   5
  832    ,   5
  ...
  1299   ,   5
  1300   ,   5

  1400   ,   2
  1401   ,   2
  ...
  1429   ,   2
  1430   ,   2

How can I do this using SQL in MSSQL 2005?

EDIT: thanks everyone, great answers. Got a few to work. I just forgot to say though that the start/end was really a time stored as an int, so 0830 to 1300 should go upto 0859 then 0900. I can’t expect you guys to answer that in this same question, i’ll work around it. Thanks again

  • 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-16T07:13:38+00:00Added an answer on May 16, 2026 at 7:13 am

    Using a CTE:

    with number_cte(n) as 
     (select n from (select 0 n) m union all select n+1 n
      from number_cte where n< 2400)
    select start+n instance, total
    from 
    datatable
    join number_cte on start+n between start and [end]
    where start+n - 100*floor((start+n)/100) between 0 and 59
    order by 1
    option (maxrecursion 2401)
    

    (Increase n< … and maxrecursion numbers as appropriate, if ranges greater than 2400 are required.)

    Edited to prevent non-valid Instance (ie. time values ending between 60 and 99) values being included.

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

Sidebar

Related Questions

I have a an XSD that looks like this (roughly) <xs:schema id=Appointment targetNamespace=http://tempuri.org/Record.xsd elementFormDefault=qualified
I have a JSON result that contains numerous records. I'd like to show the
I have a DATETIME field. I would like to select all the records that
I have a table that records a sequence of actions with a field that
I've got a record set that consists of a start and end time in
I have currently created a facebook like page that pulls notifications from different tables,
Lets say, i have the following table | start | end | activity +---------------------+---------------------+---------
I have 2 tables. for this example I will use only one users records.
I have a tree of active record objects, something like: class Part < ActiveRecord::Base
If I have records: Row Date, LocationID, Account 1 Jan 1, 2008 1 1000

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.