SQL Select if in range or more than the range value

Thursday, July 3, 2014

tblRate



RMAX RMIN RATE
100 95 10
94 90 9


I already got the select of RATE between given Maximum and Minimum Range with this query below:



SELECT ISNULL(RATE,0) AS RATE FROM tblRate WHERE RMAX >= @r AND RMIN <= @r


My problem is I want it to select the rate even if it @r value is more than the RMAX. Example, if @r is 101, it should still get the RATE value of 10 since it is more than the maximum. I tried to use this query (below) but when I tried @r value as 94, it returns the RATE 10.



SELECT ISNULL(RATE,0) AS RATE FROM tblRate WHERE RMAX >= @r AND RMIN <= @r OR (@r > (SELECT MAX(RMAX) FROM tblRate))


Help?







http://ift.tt/1kl3G74