Solved

SQL sort values alphabetically then Numercially

Posted on 2009-05-18
2
454 Views
Last Modified: 2012-05-07
I have a table in a form that I want to show the values in ascending alphabetical order and then nemerical. currently if you sort alphbetically it places the numeric values first. how can I get it to put the alphbetic valuse first? Using MS SQL 2005
0
Comment
Question by:Bill Warren
2 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 24415055
select * from tablename
order by case when isnumeric(fieldname) = 1 then 2 else 1 end asc, fieldname asc
0
 
LVL 3

Expert Comment

by:EricKaplan
ID: 24517687
It's quite dependent on the values you wish to sort, you could use the mentioned query or use padding to make the number value evaluate as alphanumeric.

You could use a function to calculate and return a "sortable" value.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

777 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