I have a table of ranges that looks like
CREATE TABLE [dbo].[WeightRange](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Description] [nvarchar](50) NULL,
[LowerBound] [decimal](18, 2) NULL,
[UpperBound] [decimal](18, 2) NULL,
[GroupID] [int] NULL
)
Given a weight and group id I need to find the matching (or nearest) range id.
Example
WeightRanges
1, 0-100kgs, 0, 100, 1
2, 101-250kgs, 101, 250, 1
3, 501-1000kgs, 501, 1000, 1
If the weight is 10 the it should return id 1, if the weight is 1500 it should return id 3, and if the weight is 255 it should return id 2. I have left the group out of the example for simplicity.
At this stage I don't really want to change the database design.