Solved

sort the alpha numeric value

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now