SQL Find a number between the given ranges of number / Find a row which has range of given number

5 pts.
Tags:
MSSQL
SQL
SQL tables
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....

Answer Wiki

Thanks. We'll let you know when a new response is added.

You could achieve that this way:

select *
from your_table
where 60 between range_start and range_end

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    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.
    69,990 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following