# How to check for a range of values • ### Question

• I have a table in a SQL DB as below

MinimumSpend    MaximumSpend    CustomerDiscount
0                             100                        10
101                          200                       20
201                          300                        30
301                          400                        40

What the above means is if a customer spends between 0 and 100 dollars they get a 10% discount. If they spend  between 301 and 400 dollars they get 40% discount.

What im trying to figure out is how to check if a range exists when a user enters the MinimumSpend and MaximumSpend spend values. So far i have (MinSpend and MaxSpend are variables being passed in)

`Discount GetValue = GetAllDiscounts().Where(d => d.MinimumSpend <= MinSpend || d.MinimumSpend >= MaxSpend && d.MaximumSpend >= MaxSpend || d.MaximumSpend <= MinSpend).FirstOrDefault();The above doesnt work so im a little lost with the code im using. How could i check to see if a range exists by that i mean if the user entered:MinimumSpend: 150MaximumSPend: 250I know that already has a match so i would like to avoid it from happening?Thanks`
Thursday, June 26, 2014 7:45 PM

• Hello,

>>What im trying to figure out is how to check if a range exists when a user enters the MinimumSpend and MaximumSpend spend values.

It seems that if use enters 150 and 250, then they should get a 20 discount, is it right? If it is, you just need to check the minimum spend as:

```int MinSpend = 150;

int MaxSpend = 250;

List<Spend> spends = new List<Spend>() {

new Spend() { MinimumSpend = 0, MaximumSpend = 100, CustomerDiscount = 10 },

new Spend() { MinimumSpend = 101, MaximumSpend = 200, CustomerDiscount = 20 },

new Spend() { MinimumSpend = 201, MaximumSpend = 300, CustomerDiscount = 30 },

new Spend() { MinimumSpend = 301, MaximumSpend = 400, CustomerDiscount = 40 }};

var result = spends.Where(d => d.MaximumSpend >= MinSpend).FirstOrDefault();
```

If I misunderstand, please let me know.

Regards.

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.