DragonBorn DragonBorn - 5 months ago 41
SQL Question

Convert YYYYMM to MMMYY

I have a period 201604 (nvarchar). I am wondering is there a way that I can convert

201604
to
APR16
? Help will be appreciated!

Answer

Use DATENAME & SUBSTRING function

How about this

declare @str nvarchar(50) = '201604'

select UPPER(left(datename(mm,cast(@str+'01' as date)),3))+substring(@str,3,2) --Apr16