In T-SQL what is the best way to convert a month name into a number?
E.g:
\'January\' -> 1 \'February\' -> 2 \'March\' -> 3
You can use below code
DECLARE @T TABLE ([Month] VARCHAR(20)) INSERT INTO @T SELECT 'January' UNION SELECT 'February' UNION SELECT 'March'` SELECT MONTH('01-' + [Month] + '-2010') As MonthNumeric,[Month] FROM @T ORDER BY MonthNumeric