Jump to content

SQL custom ORDER BY


This topic is 4134 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I would like to order my results by name of month.

 

If CHARINDEX was an option, this would be nice:

 

ORDER BY 
CHARINDEX(LEFT(month_name, 3)
, 'JAN', 'FEB', 'MAR', 'APR,' 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC')
 
Here are my results for a google chart I am potting, I just need the proper order.
['Apr', 8],
['Aug', 7],
['Feb', 42],
['Jan', 30],
['Jul', 39],
['Jun', 26],
['Mar', 36],
['May', 31],
['Nov', 36],
['Oct', 17],
['Sep', 40]
 
 
 

 

Link to comment
Share on other sites

Thanks Claus, processing the query with substitue did the trick, after I switch the query to return the month number instead of month name.

If the data you are selecting from contains both month name and number, can't you sort by month name, but select month number?

Link to comment
Share on other sites

This topic is 4134 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.