我的查询的一部分是这样的:
SELECT * FROM TableA
WHERE ColumnA >= DATEADD(DAY, - 30, GETDATE())
使用上面where子句中的表达式,您可以连续获取30天的数据,而不必提供值。现在,该报告的用户希望看到它表示为:
2nd April – 1st May
报告运行时。知道我没有参数,因为要求是不要使用参数,如何引用“> = DATEADD(DAY,-30,GETDATE())”以在报告中反映开始日期和结束日期?
SSRS没有对序号的内置支持(即“ 1st”或“ 2nd”而不是“ 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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句