Following should do:
FORMAT(Fields!Date.Value, "MMM-yy")
source: here.
Question
I have a SQL query which displays yyyymm
in the following:
select ([dimdate_fact_transac_TrnServiceDtId].[date_period]) as [date_period]
from [db].[dbo].[table]
Displays:
date_period
201304
201305
201306
How can I modify so the date_period
comes out as MMM-YY
like this:
date_period
APR-13
MAY-13
JUN-13
I am trying to do that for my SSRS report, but when I change the number format it doesn't show the date, which makes me believe it is sending it as a string rather than a date format.
Please help...
La solution
Autres conseils
Method 1a
For SQL 2012
You can use the Format
and DateFromParts
method
SELECT FORMAT(DATEFROMPARTS(date_period/100, date_period % 100, 1), 'MMM-yy')
Method 1b
Handle it in SQL 2008/2005
SELECT
LEFT(DATENAME(MONTH,
CAST(date_period AS VARCHAR(6)) + '01'
),
3)
+
'-'
+
RIGHT(datePART(YY, CAST(date_period AS VARCHAR(6)) + '01'
),
2)
as myDatePeriod
Method 2
Handle it in SSRS
=LEFT(MonthName
(RIGHT(Fields!D.Value,2))
,3)
& "-"
& Mid(Fields!D.Value,3,2)
Note: Added extra CRLF/spaces to make code readable