I am working in mssql database. I have the following scenario,
I have values in row as
2-5,10-12,67-89….
I need a sql query to fetch only those rows which has atleast one range that contains the user input.
For ex if the user input is 4, then there should be atleast one range that contains 4 like (1-5).
Is it possible to achieve the same with single query.
Try this:
SQL Fiddle Demo
If these ranges are stored as a single varchar string, then you have to parse these comma separated ranges first like so:
SQL Fiddle Demo