Solved

sort the alpha numeric value

Posted on 2002-05-04
4
1,946 Views
Last Modified: 2008-02-01
Hi all,

   I am using foxpro db!

   I have a string field in a table. But the value in this field will be in the alphanumeric format.
For e.g., String123, String23, Strinf150, String30, and String1111. Now if I fetched the data by sorting
on this field, the data is written as, String1111, String123, Strinf150, String23, and String30. but
I need the output in the following order,
String23, String30, String123, Strinf150, and String1111

i.e., if the data is compared in the alphanumeric format I could got the expected result but it is comparing
as a string. Is there any command to specify to sort the values based on alpha numeric instead of just
a string?

    I had posted the same question in the Foxpro topic, I got some comments "
"select * from test order by val(substring(chkColumn,7))"

  but if I execute this statement, it gives "Column " is not found" error message.

  but a statement like this with appropriat function works in the MS-SQL enviroment.

  I will be very thankful for your answers!

siva
0
Comment
Question by:ksivananth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 6989777
have you tried:

select substring(chkColumn, 7) as orderCol, * from test order by orderCol
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6989799
or

select substring(chkColumn, 7) as orderCol, * from test order by val(orderCol)
0
 

Accepted Solution

by:
dmkoelle earned 100 total points
ID: 6992048
I have written a Java comparator that does exactly what you're looking for.  See http://www.davekoelle.com/usability/alphanum.html

If you're looking for a "select" statement instead of Java code, I recommend asking your question in a different forum.

Hope this helps!
Dave
0
 
LVL 26

Author Comment

by:ksivananth
ID: 7005909
Hi dmkoelle,

   Really the comparator class was very usefull for me. I thought it will be very slow in performance so I avoided intially. Then I did put a try, I couldn't find that much differences in performance.

   In your code, to check the digit you need not use that algorithm because it is already available in the Java's Character class. Anyway thanks a lot!

with cheers
siva
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question