Charlestown
(1)
ClientName
(1)
Dalhousie
(1)
Batilla
(1)
Charecters
(1)
Fb22
(1)

using between with character values

Asked By mohaaro
11-Apr-08 02: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

Because Da comes AFTER D alphabetically.

Asked By Aaron Bertrand [SQL Server MVP]
10-Apr-08 06: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

Hello Aaron,set me right if i'm wrong, as far as i understand you want to

Asked By Karim Moussa
10-Apr-08 06:25 PM
Hello Aaron,

set me right if i'm wrong, as far as i understand you want to return the
clientName that it's first letter is between range of charecters, If I'm
right then you should use this method:

select clientName from table_Name where clientName like '[A-p]%'

let me know if this is not what you want?


Regards,
Karim Mohamed

Thank you both.The syntax clientName like '[A-D]%' worked very well.

Asked By mohaaro
11-Apr-08 02: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
Asked By Karim Moussa
11-Apr-08 09: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
Post Question To EggHeadCafe