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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Corrective Numbering

Status
Not open for further replies.

TheCandyman

Technical User
Sep 9, 2002
761
US
I have a list of values which i would like to sort better. They come out sorted this way using SQL on a MS Access DB when i sort by this field.
Code:
T1
T10
T11
T13
T2
T21
T22
T3
T4
T5

I would like them to be:
Code:
T1
T2
T3
T4
T5
T10
T11
T13
T21
T22


Is this even possible with classic ASP? Can I toss these into an array and get a better listing this way?
 
[0] How about directly sort from the dbase? In the sql, you issue the order by (for ms access) on the substring of the field (x, say) of table (t, say) as integer (or numeric). This is the simplest case.
[tt]
select * from t order by cint(mid(x,2))
[/tt]
Only you've to assure x is not null and has at least one number after a single starting letter.

[1] Sorting resultset contains actually the same idea, but would be quite clumsy.
 
I tried your code suggestion but end up with an error:

Code:
Microsoft JET Database Engine error '80040e07'
Data type mismatch in criteria expression.

I believe this is because CInt() is not a SQL function -- it is an Access/VB/VBA function.

This might not be possible??
 
>They come out sorted this way using SQL on a MS Access DB when i sort by this field.
I don't know... I see "MS Access" in the quote.
 
TheCandyman,

Did you verify that "x is not null and has at least one number after a single starting letter", as tsuji noted?
 
Some have those codes and others don't. Maybe your right and a null value is creating the error.
 
[2] If the resultset of the sql I posted figuratively is too large, this may be too restrictive or maybe just the right size, who know!
[tt]
select * from t where (not isnull(x) and isnumeric(mid(x,2))) order by cint(mid(x,2))
[/tt]
[0.1] Attention is also drawn to my precision
>[self][tt] Only you've to assure x is not null and has at least one number after a single starting letter.[/tt]
before complaining error...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top