Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have "January",'February", "March"..."December" as ClosingMonth.
I need to sort this and I have the following
sqlString = "SELECT * FROM CustomerListTable ORDER BY ClosingMonth Asc"

But, April comes first.
How I can make January comes first?
Is there any SQL function to change "January" to 1?

What I have tried:

sqlString = "SELECT * FROM CustomerListTable ORDER BY ClosingMonth Asc"
Posted
Updated 1-Dec-19 2:13am
Comments
Member 13194079 30-Nov-19 15:07pm    
Or, Can I make my own function to change "January" to 1, and insert this function in SQL statement? Could you give any example SQL statement with my own function ConvertMonthToNumber(byval month as string)

Either use a table to convert them and a JOIN as part of your SELECT, or append a day and year to it and use the SQL MONTH function:
SELECT MONTH('March' + ' 1 2019')

SQL Server MONTH() Function[^]
 
Share this answer
 
Comments
Member 13194079 30-Nov-19 15:31pm    
It works
Thank you
OriginalGriff 30-Nov-19 15:41pm    
You're welcome!
Maciej Los 1-Dec-19 8:14am    
5!
In addition to solution #1 by OriginalGriff i'd suggest to convert ClosingMonth to a date[^] data type column to avoid further "on-demand conversions" and due to the performance of query execution.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900