Find Greater Alphanumeric Character (1 Viewer)

Djblois

Registered User.
Local time
Today, 08:16
Joined
Jan 26, 2009
Messages
598
I have a sql query where I need to do a DSUM to create a running total. So it will add the value of the previous with its own. The issue is the field I comparing is an alphanumeric character it can be 200, 201, 202 but also 200A, 200B, etc.
So I cannot do a simple > symbol. how do I determine that 201 is greater than 200A and 200B is greater than 200A, etc.


Here is the sql that I need to modify:


Code:
RunningTotal: DSum("TotalAmount","qryRunningTotalForDailyCash","RouteID<=" & [RouteID])


btw RouteID is the one that is the alphanumeric field.
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:16
Joined
Sep 21, 2011
Messages
14,356
Code:
? "200B" > "200A"
True
? "200" > "200A"
False
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:16
Joined
Oct 29, 2018
Messages
21,496
And...
Code:
?"201" > "200A"
True
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:16
Joined
Sep 21, 2011
Messages
14,356
However unless you have set length values

Code:
? "50" > "200A"
True

so what does your data look like.?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 16:16
Joined
Sep 12, 2006
Messages
15,660
you can do a > with letters - it's just a dictionary sort which is what you want.

The problem is with numbers of different lengths then sort "incorrectly" as numbers. Is that wnat you mean?

so 1,2,3,4... `100,101,102 sort as
1,101,102,2,3,4
 

rpeare

Registered User.
Local time
Today, 08:16
Joined
Sep 15, 2016
Messages
18
I think there's a fairly easy solve here.

If you break your route number into the numeric portion and the alpha portion in your query, then sort on those two fields you should be golden.

i.e.

RN: left([Route_ID], 3)
RA: right([Route_ID], len([Route_ID]) -3)

This assumes the numeric portion is *always* 3 characters long. If it's not how is the routeID getting generated, is it possible for you to get the numeric portion independently and/or the alpha portion independently of looking at the Route_ID?

If neither of those is possible you can probably create a custom function to return the position of the last numeric value in your string and use that in the same formulas above.
 

Users who are viewing this thread

Top Bottom