tighten range limit check on SQL query build