New Page 1
Here is a different way to get the month in
number for character month.
This is simple and you need not to use Date
functions.
--For first 3 characters of
months
DECLARE @MONTHS
AS CHAR(36)
SET @MONTHS =
'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'
SELECT (CHARINDEX('OCT',
@MONTHS)/3)+1 AS NUMERIC_MONTH
--For all characters of months
DECLARE @MONTHS
AS CHAR(108)
--IF CODE DOES NOT WORK PROPERLY
--CHECK WHETHER EVERY MONTH (INCLUDING THE SPACES) HAS 9 CHARACTER IN LENGTH
SET
@MONTHS =
'JANUARY FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBEROCTOBER NOVEMBER DECEMBER '
SELECT (CHARINDEX('DECEMBER',
@MONTHS)/9)+1 AS NUMERIC_MONTH
Cheers,
Raghavendra_Narayana@hotmail.com
|