Try this (in this example, @Date represents @terminationMonthYear):
DECLARE @Date NVARCHAR(50) = 'February ,2013' DECLARE @Month NVARCHAR(50) = LTRIM(RTRIM(LEFT(@Date, PATINDEX('%,%',@Date)-1))) DECLARE @Year NVARCHAR(50) = LTRIM(RTRIM(RIGHT(@Date, LEN(@Date) - PATINDEX('%,%',@Date)))) SELECT CAST(@Month + ' 01, ' + @Year AS DATE)
OR if your input parameter includes the (), then try this:
DECLARE @Date NVARCHAR(50) = '(February ,2013)' SET @Date = REPLACE(REPLACE(@Date,'(',''),')','') DECLARE @Month NVARCHAR(50) = LTRIM(RTRIM(LEFT(@Date, PATINDEX('%,%',@Date)-1))) DECLARE @Year NVARCHAR(50) = LTRIM(RTRIM(RIGHT(@Date, LEN(@Date) - PATINDEX('%,%',@Date)))) SELECT CAST(@Month + ' 01, ' + @Year AS DATE)
This will work whether you pass in the full month name or the 3-letter abbreviation (e.g. Mar for March). Also, you mentioned you wanted to convert it into DATETIME format, but 2013-01-01 is a DATE (no time component). If you want a time component, you can just change the CAST in the last line to "... AS DATETIME" and it will add a time component (though it will be all 0's).