Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using "Between" operator with strings

Status
Not open for further replies.

huskerdon

Programmer
Aug 26, 2002
67
US
Hi everybody,

I've never noticed this issue before, but it's got me baffled. I'm making a search form, and am building various SQL strings on the fly. I have to allow for comparisons whether the fields are text, numerical, or dates.

I've got most of it figured out, except I want the users to be able to enter a range of 2 values, including strings. The beginning and ending values are entered into 2 text boxes. Then the appropriate characters, (" or #) are added as necessary when building the SQL string. The numerical and date values work fine, but I'm having a problem with text values, because I'm inserting the * wildcard via code. The wildcard will go at the end (or both beginning and end), depending on the user's selection. Of course when using the "Between" choice with strings, I want the wildcard only at the END of each selection.

Here's an example: I'm filtering on the Location field.
There are 191 records that start with "A"
2 of these start with A followed by a space, i.e. "A Street..."

There are 533 records that start with "B"
340 of these start with B followed by a space, i.e. "B & B..."

If I do a filter where [Location] = "A*" it returns 191 - Correct!

If I do a filter where [Location] = "B*" it returns 533 - Correct!

Now if I do a filter where [Location] between "A*" and "B*" it returns only 529 records. The total that I want is 724, but it is missing 195 records. Strangely this total is the 2 "A" records starting with "A ", plus the 193 "B" records where it does NOT start with "B ".

I have figured out that if I append a "z" to the second value, i.e. make it [Location] between "A*" and "Bz*", it will catch all of the "B" records for a total of 722. But then it still misses the 2 "A" records starting with "A ".

This is very confusing, but if anyone has a solution, I would greatly appreciate it. If nothing else, I can just disable the "Between" choice when filtering on text fields.

Thank you very much,

huskerdon
 
Never Mind :)

I figured it out. I need to use Like "[A-B]*"

I was focusing on using "between ..." and forgot about using the [range] follwed by a *, with the "like" operator.

Hopefully this will help someone else, too!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top