5 pts.
 SQL Find a number between the given ranges of number / Find a row which has range of given number
I am facing a problem in MSSQL: - I have a table in MSSQL, which has 10 rows & 5 columns. In this table I am maintaining a numeric range in 2 columns. First one has starting number & second column has end number. All rows have unique values in these 2 columns. For Ex.: - In first row the value in first column is 1 & in second column is 100. In another row the value in first column is 101 & in second column is 200 & so on.... Now my problem is how can we identify that a given number is coming in which range & in which row? For ex.: - If we say number 60. Then how can we identify in MSSQL in this table the given number is coming in which range & in which row without using CURSOR?? I need to know the function or command or query or any other utility in MSSQL by which the above-mentioned task could be achieved? Please suggest & thanks a lot in advance....

Software/Hardware used:
ASKED: December 5, 2008  2:53 PM
UPDATED: December 5, 2008  5:31 PM

Answer Wiki:
You could achieve that this way: select * from your_table where 60 between range_start and range_end
Last Wiki Answer Submitted:  December 5, 2008  5:28 pm  by  carlosdl   63,580 pts.
All Answer Wiki Contributors:  carlosdl   63,580 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

You could also change the WHERE clause to something like this:

where range_start <= 60
and range_end >= 60

but I would prefer to use BETWEEN.

 63,580 pts.