Because Da comes AFTER D alphabetically. - Aaron Bertrand [SQL Server MVP] |
Thursday, April 10, 2008 6:27 PM
|
Because Da comes AFTER D alphabetically. If you ordered by client name,
would you expect this order:
B
Batilla
Charlestown
D
Dalhousie
Or this order:
B
Batilla
Charlestown
Dalhousie
D
Since between logically stops at 'D', the latter must be what you expect if
you think 'Dalhousie' should be between B and D.
Maybe you meant:
LEFT(ClientName, 1) BETWEEN 'B' and 'D'
?
Same,
LEFT(CLientName, 1) BETWEEN 'V' AND 'Z'
If there is an index on ClientName, this may be more efficient:
ClientName LIKE '[B-D]%'
ClientName LIKE '[V-Z]%'
A |
 |
using between with character values - mohaaro |
Friday, April 11, 2008 2:50 AM
|
I've figured out the doing this.
clientName between 'B' and 'D'
Gets converted into this.
clientName >= 'B' and clientName <= 'D'
So in the end the two statements are the same. Can anyone explain why
values starting with the letter D are not returned by these two
queries?
Since 'D' is not returned how would I go about returning the Z values
of this?
clientName between 'V' and 'Z'
My first try at returning 'Z' is the follow but it seems like there
should be a better way.
clientName between 'V' and 'Z' or clientName >= 'Z'
Regards,
Aaron |
 |
Thank you both.The syntax clientName like '[A-D]%' worked very well. - mohaaro |
Friday, April 11, 2008 2:50 AM
|
Thank you both.
The syntax clientName like '[A-D]%' worked very well. The use of the
index in this case is a nice bonus.
Aaron |
 |
using between with character values - Karim Moussa |
Friday, April 11, 2008 9:23 AM
|
Aaron,
I am glad that you have solved your problem.
Regards,
Karim
Thank you both.
The syntax clientName like '[A-D]%' worked very well. The use of the
index in this case is a nice bonus.
Aaron |
 |