I have a table that contains the "Start and End" columns, like INT. I need to find the very first available range Ncompared to existing data.
Table layout :
CREATE TABLE [dbo].[MSRange]
(
[RangeId] [int] IDENTITY(1,1) NOT NULL,
[RangeStart] [int] NOT NULL,
[RangeEnd] [int] NOT NULL,
CONSTRAINT [PK_MSRange]
PRIMARY KEY CLUSTERED ([RangeId] ASC)
) ON [PRIMARY]
Sample Data:
INSERT INTO [dbo].[MSRange] ([RangeStart], [RangeEnd])
VALUES (1, 150), (1250, 1500), (3100, 7500), (10500, 15000);
Requirements:
I need to find a placeholder for 1000 slots, obviously, from the given seeds, which we can say is available from 151 to 1150. Similarly, for 1,500 slots, 1501-3000 are available.
Please help me how to get the first placeholder available.
source
share