Convert varchar Mon-yyyy to date

My date field is DATE (varchar(8))  and is in the format Mon-YYYY (ex: Apr-2010).  How do I convert to a date using the 1st of the month.  I tried several solutions I found here and on the web but couldn't get any to work.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


SELECT cast('01-' + @v AS DATETIME)
CarenCAuthor Commented:
I don't know how or where to use the DECLARE statement.  All I know to do is run a SELECT.
I was just doing that to show the syntax.  If the field in your table is MyDate then use

SELECT ELECT cast('01-' + MyDate AS DATETIME) AS MyDate FROM myTable

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Hi lludden,
I think the following might help.

SELECT STR_TO_DATE(concat('01-',myDate) , '%d-%M-%Y')   FROM myTable

CarenCAuthor Commented:
lludden's solution worked.  rkannan2000's didn't work . . . the error was str_to_date is not a valide function.
Scott PletcherSenior DBACommented:
YYYYMMDD is a 100% safe format *and* will fit in the existing space if you want to permanently change the column's data.

    RIGHT(date, 4) + RIGHT('0' + CAST((CHARINDEX(LEFT(date, 3),
        'JanFebMarAprMayJunJulAugSepOctNovDec') + 2) / 3 AS varchar(2)), 2) + '01' AS date
FROM dbo.tablename

UPDATE dbo.tablename
SET date = RIGHT(date, 4) + RIGHT('0' + CAST((CHARINDEX(LEFT(date, 3),
        'JanFebMarAprMayJunJulAugSepOctNovDec') + 2) / 3 AS varchar(2)), 2) + '01'
CarenCAuthor Commented:
Scott . . . good suggestion but can't make that change in this situation.
Scott PletcherSenior DBACommented:
Would still work as a SELECT, of course :-) :

    CAST(RIGHT(date, 4) + RIGHT('0' + CAST((CHARINDEX(LEFT(date, 3),
        'JanFebMarAprMayJunJulAugSepOctNovDec') + 2) / 3 AS varchar(2)), 2) + '01' AS date) AS date
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.