?
Solved

SQL sort values alphabetically then Numercially

Posted on 2009-05-18
2
Medium Priority
?
484 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
[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 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 2000 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

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. …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Suggested Courses

801 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