SQL Query Help from '4/14' to 'Apr-14'

Experts - I have a table which has more than a million rows. due to bad data format, i have a column which has data like

4/14
3/14
3/13
2/15
etc

I need to convert them to
Apr-14
Mar-14
Mar-13
Feb-15

Kindly help.
LVL 7
ManjuIT - Project ManagerAsked:
Who is Participating?
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.

Brian CroweDatabase AdministratorCommented:
My first response is don't do that.  Store them as dates.  In case that isn't possible...

I will assume that the year is 2015 in those incomplete dates or that it doesn't matter.

DECLARE @String      VARCHAR(10) = '4/15'

SELECT REPLACE(CONVERT(VARCHAR(6), CONVERT(DATETIME, @String + '/2015', 101), 7), ' ', '-')
0

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
Mike EghtebasDatabase and Application DeveloperCommented:
	Declare @dt varchar(10) = '4/14'
	select Case left(@dt,CHARINDEX('/',@dt)-1)
	          when 1 then 'Jan'
			  when 2 then 'Feb'
			  when 3 then 'Mar'
			  when 4 then 'Apr'
			  when 5 then 'May'
			  when 6 then 'Jun'
			  when 7 then 'Jul'
			  when 8 then 'Aug'
			  when 9 then 'Sep'
			  when 10 then 'Oct'
			  when 11 then 'Nov'
			  when 12 then 'Dec'
		 end + substring(@dt,CHARINDEX('/',@dt),3)

Open in new window

0
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 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.