Solved

sort the alpha numeric value

Posted on 2002-05-04
4
1,951 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

635 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