Avatar of MichaelSwitzer
MichaelSwitzer
 asked on

Group set of number by Min and Max sets

I'm looking for some code or method that will display the min and max of sequenced number sets.
Situation:
I have a table with with record entries like:

1
2
3
4
6
7
8
22
23
24

and i would like an output of:

Min      Max
1           4
6           8
22        24
Microsoft SQL ServerDatabasesMicrosoft SQL Server 2005

Avatar of undefined
Last Comment
MichaelSwitzer

8/22/2022 - Mon
Ray

I don't understand the question?  What are you trying to accomplish?
MichaelSwitzer

ASKER
The actual application is a little more complicated than the example I provided... Sorry for the poor reduction...

Assume a table named RawData. In the table RawData, 10 rows exist with the following values:

UniqueID     Column1
    1                  5
    2                  6
    3                  7
    4                  9
    5                 67
    6                 68
    7                 69
    8                 70
    9                 71
   10                72

I am looking for a store procedure or Table-Valued Function that will yield the follow results:


     Min               Max
     5                    7    
     9                    9
    67                  72

Notice the MIN and MAX are the min and max of a CONSECUTIVE set of numbers essentially grouped together.

I hope this helps...

Thank you rlistenb
MichaelSwitzer

ASKER
i understand the solution is multi-part. it probably involves a stored procedure and a scalar-valued function or two...
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
SOLUTION
Mark Wills

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
ee_rlee

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
MichaelSwitzer

ASKER
ee_rlee, I used your solution because it is a bit faster and more eloquent.
Thank you both for your quick responses and help. Great Job!