Using SQL Server 2005
Given a table:
| Role | Low | High |
| A | AA00 | ZZ* |
| B | * | |
| C | AA00 | AZ99 |
How would I go about performing a query that selects rows where a value falls within the LOW – HIGH range.
e.g. I would like to select Roles A and B if I am comparing Low and High to ‘BB’ and role B if I am comparing the range to ’22’
AB99 should return A, B, C
Try this:
I’m assuming that both your
*andNULLvalues are used like wildcard values. This produces proper results for each of your example cases.Note that this also depends on which collation you’re using. For most (including the default collation
SQL_Latin1_General_CP1_CI_AS) it will be just fine.EDIT: Looking more closely you may want to replace the
WHEREclause with this: