简体   繁体   English

SSRS日期排序

[英]SSRS date sorting

I have a date that I want to show as Month then Year like 'Jan 05'. 我有一个日期想要显示为“月”然后“年”,例如“ Jan 05”。 I have used the following SQL datename(month,eFolder.eCreationTime) + ' ' + datename(year,eFolder.eCreationTime) as "MonthYear" in my query. 我在查询中使用了以下SQL datename(month,eFolder.eCreationTime)+''datedate(year,eFolder.eCreationTime)作为“ MonthYear”。

However on SSRS I am finding it difficult to sort this in a column grouping as its showing in Alphabetical order. 但是在SSRS上,我发现很难按字母顺序将其按列分组进行排序。 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. 无论如何,还是有问题要解决,还是问题在于上面提到的SQL的连接问题,我尝试在组级别和文本框中进行排序却没有成功。

Thank you in advance 先感谢您

This is how the sql looks like at the minute 这是sql在当下的样子

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. 不要在SQL中进行字符串转换。 Return the data as a date value and do the string formatting in SSRS. 返回数据作为日期值,并在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 ) 只需返回代表该月的日期即可(例如2015-10-01

Other options: 其他选项:

  • Groups by the Year and Month as numbers an include them in your results and turn that into a date in SSRS 按年和月分组的数字包括在结果中,并将其转换为SSRS中的日期
  • Parse the string to a date in SSRS (using CDate or DateTime.ParseExact() ) 将字符串解析为SSRS中的日期(使用CDateDateTime.ParseExact()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM