Following is the table and script of this table.
DECLARE @temp TABLE (PPId INT, SVPId INT, Minimum INT, Maximum INT)
INSERT INTO @temp VALUES(1,1,8,20)
INSERT INTO @temp VALUES(2,1,21,100)

Minimum & Maximum are passed in as parameter. I want to find all rows that fall in the given range.
E.g.;
- If @minimum = 9 and @maximum = 15
then it falls in the range of first
row. - If @minimum = 21 and @maximum = 22
then it falls in the range of 2nd
row. - If @minimum = 7 and @maximum = 25
then it falls in the range of both
rows so both rows should be returned.
Thanks.
When comparing ranges like this, it’s easier to look for the case where ranges don’t overlap. There are many different ways that two ranges can overlap, but there is only two ways that the don’t overlap: