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 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

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use TRIM in the ORDER BY: ORDER BY… May 16, 2026 at 4:45 pm
  • Editorial Team
    Editorial Team added an answer If you're just trying to get the last part of… May 16, 2026 at 4:45 pm
  • Editorial Team
    Editorial Team added an answer On the front end, do something like this: <html xmlns="http://www.w3.org/1999/xhtml"… May 16, 2026 at 4:45 pm

Trending Tags

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

Top Members

Related Questions

This is a slightly tricky question. I am using NSDateFormatter on the iPhone but
I have a tricky problem that has had me scratching my head for a
I've got a slightly tricky problem to solve; imagine this: One of my applications
This question is slightly different from the kind of finding longest sequence or substring
This is slightly related to the question asked here yet the answer does not
I have a bash function (slightly simplified for explaining) copy_to() { cp $1 $2
I have 2 databases with the same data, but slightly different data types in
This is similar to a previous question , but the answers there don't satisfy
Alright...I've given the site a fair search and have read over many posts about
I have been playing around with Apache CXF, in particular the various data bindings

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.