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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:43:21+00:00 2026-05-16T02:43:21+00:00

A slightly tricky SQL question (we are running SQL server 2000). I have the

  • 0

A slightly tricky SQL question (we are running SQL server 2000).

I have the following table, StoreCount –

WeekEndDate    StoreCount
2010-07-25     359
2010-07-18     359
2010-07-11     358
2010-07-04     358
2010-06-27     358
2010-06-20     358
2010-06-13     358
2010-06-06     359
2010-05-30     360
2010-05-23     360
2010-05-16     360

I want to turn this into the following output –

StartDate    EndDate       StoreCount
2010-07-18   2010-07-25    359
2010-06-13   2010-07-11    358
2010-06-06   2010-06-06    359
2010-05-16   2010-05-30    360

As you can see, I’m wanting to group the store counts, by only as they run in sequence together.

  • 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-16T02:43:22+00:00Added an answer on May 16, 2026 at 2:43 am

    Here’s a kick at the can, only it may have syntax not available in SS2k. It was actually written on Oracle as I don’t have that version of SS around anymore. The only catch might be the the select of a select…(it’s been a while since I’ve used SS2k, so it’s hard to remember what features weren’t available back then.)

    select min(weekenddate) as start_date, end_date, storecount
    from (
    select s1.weekenddate
         , (select max(weekenddate)
              from store_stats s2
             where s2.storecount = s1.storecount
               and not exists (select null
                                 from store_stats s3
                                where s3.weekenddate < s2.weekenddate
                                  and s3.weekenddate > s1.weekenddate
                                  and s3.storecount <> s1.storecount)
           ) as end_date
         , s1.storecount
    from store_stats s1
    ) result
    group by end_date, storecount
    order by 1 desc
    
    
    START_DATE END_DATE   STORECOUNT
    ---------- ---------- ----------
    2010-07-18 2010-07-25        359
    2010-06-13 2010-07-11        358
    2010-06-06 2010-06-06        359
    2010-05-16 2010-05-30        360
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a slightly tricky question. I am using NSDateFormatter on the iPhone but
I am running into some slightly tricky issues with a legacy db. Everything seems
Slightly more advanced mapping then in my previous question :) Tables: create table [Primary]
A slightly archaic question I'm afraid but here goes: I have a program which
Question slightly in the abstract... We have a situation where we have a struct
I have a slightly theoretical question that I want to clear up before I
Got a slightly tricky problem I'd like some advice on. I have a source
I have a slightly tricky one here I hope the community can help me
Slightly related to my other question : What is the difference between the following:
Slightly unusual requirement here, which unfortunately is down to a poor table design a

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.