Alex Rivera | Logout

SQL Between clause with strings columns

Asked 2011-05-12T15:51:41.563
24

I want to make a search using "between" clause over a string column. Doing some test I got this:

Let's assume that there is a country table with a "name" column of type varchar. If I execute this query:

Select * from country where name between 'a' and 'b'

I got this result:

Argentina
.
.
.
Argelia.

It excludes those countries that starts with B which I found a little bit weird.

Is there a way to do this search in a more accurate way? Any other ideas for make this search?

Thanks in advance

Edit
Report

1 Answer

0

The reason this statement didn't work is SQL pads the string with whitespace until it's the same length as the comparing string. So, in comparison, sql compared b followed by several blanks with b******. Because whitespace appears before all the other letters, sql decided b***** came after b[6 spaces]. So it shouldn't be displayed.

answered 2011-08-16T03:08:57.450

Your Answer