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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:23:57+00:00 2026-06-06T22:23:57+00:00

Sorry for the bad title – I simply do not know what to call

  • 0

Sorry for the bad title – I simply do not know what to call the thing I want to do.

Here it goes:

In MS SQL Server 2008

I have a temp table with 4000+ rows created with the WITH statement looking like this:

ID (varchar) DATE (int)

AB1135000097 | 20151221
AB1135000097 | 20160119
AB1135000097 | 20160219
AB1135001989 | 20120223
AB1135001989 | 20120323
AB1135001989 | 20120423
.
.
.

I want to pair the data in date-ranges based on DATE.

AB1135000097 | 20151221 | 20160119
AB1135000097 | 20160119 | 20160219
AB1135001989 | 20120223 | 20120323
AB1135001989 | 20120323 | 20120423

Does this action have a name ? (I will add tags to the post when I know what I’m asking for)

  • 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-06T22:23:59+00:00Added an answer on June 6, 2026 at 10:23 pm

    I found a solution to my problem. Inspired by Jonathan Leffler’s solution. Thanks a lot!

    It is based on adding row-numbers to the table ordered by ID and DATE, and then self-join with ROW+1 to get the next date as a second date column.

    with 
    SCHEDULE as
    ( -- remove duplicates and NULL entries
    
        select DISTINCT ID, DATE from TABLE1
        where DATE IS NOT NULL
    ),
    
    SCHEDULE_WITH_ROW as
    (
    select * from (
        select DISTINCT ROW_NUMBER()
            OVER (ORDER BY ID, DATE) AS
            ROW, ID, DATE 
        from SCHEDULE) AS SCHED
    )
    
    select 
        S1.ID
        , S1.DATE
        , S2.DATE
    from SCHEDULE_WITH_ROW S1
        join SCHEDULE_WITH_ROW S2 on S2.ID = S1.ID and S1.ROW + 1 = S2.ROW 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if the title is bad. But I do not know how to address
Sorry with title if it is not looks bad, I don't know how can
sorry for the bad title, I don't know how to describe my problem. I
Sorry for the bad title, I wasn't sure what else to call this question.
Sorry for the bad title, I've no idea what to call this question. I
hi sorry for the bad title but I'm not 100% sure what I need
Sorry for the bad title, but I don't know how to name this. My
Sorry for a title that bad, but i didn't know how to describe my
Sorry for bad title. I could not come up with anything better. Every example
First of all: Sorry for my bad English! I know the title isn't the

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.