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!

Order By Help

Status
Not open for further replies.

lauritz

Programmer
Aug 20, 2002
27
AU
Hi,

I want to order my recordset by a character type field that contains either "N/A" or integer values. When I sort it (asc) to get the lowest hours remaining for the currently selected object I get weird results.

for instance "10000" is less than "1250"! Am I missing something? Any help greatly appreciated.

 
for instance "10000" is less than "1250"!

You're sorting alphabetically which means Access looks at each character in turn and ignores the length of the word. You're sorting words not numbers.

Think "comes before" rather than "is less than". "111111" comes before "2" in the same way that "AAAAAA" comes before "B".

Geoff Franklin
 
Thanks Geoff. Any suggestions as to how to get around it??
 
It's clunky and it uses IIf (which I don't like becuase it can be slow) but this works:
Code:
SELECT YourTableName.YourField
FROM YourTableName
ORDER BY IIf(IsNumeric([YourField]),CLng([YourField]),Null);

[pc2]
 
ORDER BY Val([your field]), [your field]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks to everyone that helped here. Much appreciated.
It turned out the the solution that best fitted was Geoff's idea of using format$.

Thanks again .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top