Skip to content
Advertisement

Converting month name to month number in SQL Server

I have a column (says Period_name ) that accepts varchar value. Inside the column, I have inputs likeJan-19, Feb-19, etc. I need an SQL instruction whenever left of Period_name comes like Jan, Feb then it should convert into corresponding month number. For example

Input

Output

The SQL query condition is as follows:

Thanks 🙂

Advertisement

Answer

Just another option is to try_convert() into a date

Note: the format() is optional

Example

Returns

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement