I have a date that I want to show as Month then Year like 'Jan 05'. I have used the following SQL datename(month,eFolder.eCreationTime) + ' ' + datename(year,eFolder.eCreationTime) as "MonthYear" in my query.
However on SSRS I am finding it difficult to sort this in a column grouping as its showing in Alphabetical order. Is there anyway to sort this or does the problem lie with the SQL mentioned above as its concatenating it I have tried sorting at group level and on the textbox with no success.
Thank you in advance
This is how the sql looks like at the minute
SELECT
case when SUBSTRING(eFolder.eFolderName,1,2) = 'IM' then 'Incidents'
when SUBSTRING(eFolder.eFolderName,1,2) = 'RF' then 'Requests'
else null end "Request or Incident",
count(eFolder.eFolderName) as "Log No",
eUser2.eDistinguishedName,
datename(month,eFolder.eCreationTime) + ' ' + datename(year,eFolder.eCreationTime) as "Month"
FROM
eUser eUser2 RIGHT OUTER JOIN prcIncidentManagement ON (eUser2.eUserName=prcIncidentManagement.AssignedTo)
INNER JOIN eFolder ON (prcIncidentManagement.EFOLDERID=eFolder.eFolderID)
group by
case when SUBSTRING(eFolder.eFolderName,1,2) = 'IM' then 'Incidents'
when SUBSTRING(eFolder.eFolderName,1,2) = 'RF' then 'Requests'
else null end ,
eUser2.eDistinguishedName,
datename(month,eFolder.eCreationTime) + ' ' + datename(year,eFolder.eCreationTime)
Don't do the string conversion in SQL. Return the data as a date value and do the string formatting in SSRS.
One of many reasons why dates should not be stored (or retrieved) as text.
The reason I grouped it to months is to reduce the amount of lines and time it takes.
You can still group it by month without converting it to a string. Just return a date that represents that month (eg 2015-10-01
)
Other options:
CDate
or DateTime.ParseExact()
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.