我的部分查询是这样的:
SELECT * FROM TableA
WHERE ColumnA >= DATEADD(DAY, - 30, GETDATE())
使用上面where子句中的表达式,您可以在不提供值的情况下提取滚动的30天数据。现在,报告的用户希望看到它代表:
2nd April – 1st May
报告运行时。知道我没有参数作为要求是不使用参数,我如何引用“> = DATEADD(DAY, - 30,GETDATE())”来反映报告中的开始日期和结束日期?
答案 0 :(得分:4)
SSRS没有对序数进行内置支持(即“1st”或“2nd”而不是“1”或“2”)。 This page包含自定义代码,可将此功能添加到您的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)
答案 1 :(得分:0)
右键点击Textbox
,转到Textbox Properties
然后点击Number tab
,点击custom format
选项,然后点击黑色的fx
按钮。
只需编写一行代码即可以更简单的方式完成工作:
将打开一个表单,复制下面的文本并粘贴到那里,以便在数据库日期字段中更改以下文本。
字段!FieldName.Value,"数据集"
FieldName
替换为您的日期字段将Dataset
替换为您的日期名称
=" d" + switch(int(Day((Fields!FieldName.Value," Dataset")))mod 10 = 1,"''",int(Day ((Fields!FieldName.Value," Dataset")))mod 10 = 2,"' nd'",int(Day((Fields!FieldName。价值,"数据集")))mod 10 = 3,"''",true,"''& #34;)+" MMMM,yyyy"