Reporting services 在SSRS表达式中格式化日期时间
我的部分疑问如下:Reporting services 在SSRS表达式中格式化日期时间,reporting-services,ssrs-2008-r2,ssrs-2012,Reporting Services,Ssrs 2008 R2,Ssrs 2012,我的部分疑问如下: SELECT * FROM TableA WHERE ColumnA >= DATEADD(DAY, - 30, GETDATE()) 使用上面where子句中的表达式,您可以提取滚动30天的数据,而无需提供值。现在,报告的用户希望看到它的表示方式如下: 2nd April – 1st May 当报告运行时。知道我没有参数,因为要求不使用参数,我如何引用“>=DATEADD(DAY,-30,GETDATE())”来反映报告中的开始日期和结束
SELECT * FROM TableA
WHERE ColumnA >= DATEADD(DAY, - 30, GETDATE())
使用上面where子句中的表达式,您可以提取滚动30天的数据,而无需提供值。现在,报告的用户希望看到它的表示方式如下:
2nd April – 1st May
当报告运行时。知道我没有参数,因为要求不使用参数,我如何引用“>=DATEADD(DAY,-30,GETDATE())”来反映报告中的开始日期和结束日期?SSRS没有内置的序号支持(即“1”或“2”而不是“1”或“2”)。包含将此功能添加到SSRS报告的自定义代码;然而,这有点错误。以下是更正的版本:
Public Function FormatOrdinal(ByVal day As Integer) as String
' Starts a select case based on the odd/even of num
if(day = 11 or day = 12 or day = 13)
' If the nymber is 11,12 or 13 .. we want to add a "th" NOT a "st", "nd" or "rd"
return day.ToString() + "th"
else
' Start a new select case for the rest of the numbers
Select Case day Mod 10
Case 1
' The number is either 1 or 21 .. add a "st"
Return day.ToString() + "st"
Case 2
' The number is either a 2 or 22 .. add a "nd"
Return day.ToString() + "nd"
Case 3
' The number is either a 3 or 33 .. add a "rd"
Return day.ToString() + "rd"
Case Else
' Otherwise for everything else add a "Th"
Return day.ToString() + "th"
End Select
end if
End Function
如果将此代码添加到报告属性下的报告代码部分,则文本框表达式将为:
Code.FormatOrdinal(Day(Globals!ExecutionTime)) & " " & MonthName(Month(Globals!ExecutionTime), False) & " - " & Code.FormatOrdinal(Day(DateAdd("d", -30,Globals!ExecutionTime))) & " " & MonthName(Month(DateAdd("d", -30,Globals!ExecutionTime)), False)
SSRS没有内置的序数支持(即“1”或“2”而不是“1”或“2”)。包含将此功能添加到SSRS报告的自定义代码;然而,这有点错误。以下是更正的版本:
Public Function FormatOrdinal(ByVal day As Integer) as String
' Starts a select case based on the odd/even of num
if(day = 11 or day = 12 or day = 13)
' If the nymber is 11,12 or 13 .. we want to add a "th" NOT a "st", "nd" or "rd"
return day.ToString() + "th"
else
' Start a new select case for the rest of the numbers
Select Case day Mod 10
Case 1
' The number is either 1 or 21 .. add a "st"
Return day.ToString() + "st"
Case 2
' The number is either a 2 or 22 .. add a "nd"
Return day.ToString() + "nd"
Case 3
' The number is either a 3 or 33 .. add a "rd"
Return day.ToString() + "rd"
Case Else
' Otherwise for everything else add a "Th"
Return day.ToString() + "th"
End Select
end if
End Function
如果将此代码添加到报告属性下的报告代码部分,则文本框表达式将为:
Code.FormatOrdinal(Day(Globals!ExecutionTime)) & " " & MonthName(Month(Globals!ExecutionTime), False) & " - " & Code.FormatOrdinal(Day(DateAdd("d", -30,Globals!ExecutionTime))) & " " & MonthName(Month(DateAdd("d", -30,Globals!ExecutionTime)), False)
右键单击
文本框
,转到文本框属性
,然后单击数字选项卡
,单击自定义格式
选项,然后单击黑色的fx
按钮
只需编写一行代码即可以更简单的方式完成工作:
将打开一个表单,复制下面的文本并粘贴到那里,以便需要使用数据库日期字段更改下面的文本
田野!FieldName.Value,“数据集”
FieldName
右键单击
文本框
,转到文本框属性
,然后单击数字选项卡
,单击自定义格式
选项,然后单击黑色的fx
按钮
只需编写一行代码即可以更简单的方式完成工作:
将打开一个表单,复制下面的文本并粘贴到那里,以便需要使用数据库日期字段更改下面的文本
田野!FieldName.Value,“数据集”
FieldName