date - Lookupset 中的 SSRS 最大日期

标签 date reporting-services ssrs-2008 max

我花了很长时间寻找解决方案,但没有找到我想要的。针对不同问题调整现有解决方案的努力也没有奏效!

我使用 LookupSet 返回日期列表,然后将它们连接起来以返回列表:

=Join(LookupSet(Fields!cPatSer.Value,Fields!cPatSer.Value,Fields!DDate.Value,"PatD"))

我只想显示该列表中的最新日期。这是我到目前为止所尝试过的:

  • 上面的函数封装在 Max 函数中(不起作用,因为 Join 返回一个字符串)
  • 使用 split 函数拆分结果字符串,查找逗号,然后使用 max 函数
  • 执行上述两项操作,但首先使用 CDate 和 DateTime.Parse 将输出转换为 Date 对象,如下所示...

    =Join(LookupSet(Fields!cPatSer.Value,Fields!cPatSer.Value,CDate(Fields!DDate.Value),"PatD"))

    =Join(LookupSet(Fields!cPatSer.Value,Fields!cPatSer.Value,DateTime.Parse(Fields!DDate.Value),"PatD"))

有人可以指点一下吗?

最佳答案

我找到了使用自定义代码的解决方案。 Oz Locke 创建了一个函数,可以对整数数据进行各种聚合(下面的链接),我已经修改了它以适用于日期。

在报表的 Code 属性中,粘贴以下内容:

'Amended from Oz Locke's code:
'https://github.com/OzLocke/SSRSAggLookup/blob/master/AggLookup.vb
'Allows users to adjust the aggregation type of lookupsets in a cell
Function AggLookup(ByVal choice As String, ByVal items As Object)

'Ensure passed array is not empty
'Return a zero so you don't have to allow for Nothing
If items Is Nothing Then
    Return 0
End If

'Define names and data types for all variables
Dim current As Date
Dim count As Integer
Dim min As Date
Dim max As Date
Dim err As String

'Define values for variables where required
current = CDate("01/01/1900")
count = 0
err = ""

'Calculate and set variable values
For Each item As Object In items

    'Calculate Count
    count += 1

    'Check value is a number
    If IsDate(item) Then

        'Set current
        current = CDate(item)

        'Calculate Min
        If min = Nothing Then
            min = current
        End If
        If min > current Then
            min = current
        End If

        'Calculate the Max
        If max = Nothing Then
            max = current
        End If
        If max < current Then
            max = current
        End If

        'If value is not a number return "NaN"
    Else
        err = "NaN"
    End If

Next

'Select and set output based on user choice or parameter one
If err = "NaN" Then
    If choice = "count" Then
        Return count
    Else
        Return 0
    End If
Else
    Select Case choice
        Case "count"
            Return count
        Case "min"
            Return min
        Case "max"
            Return max
    End Select
End If
End Function

然后在报告的单元格中使用以下表达式:

=code.AggLookup("max", LookupSet(Fields!cPatSer.Value,Fields!cPatSer.Value,Fields!DDate.Value,"PatD"))

https://itsalocke.com/aggregate-on-a-lookup-in-ssrs/ https://github.com/OzLocke/SSRSAggLookup/blob/master/AggLookup.vb

关于date - Lookupset 中的 SSRS 最大日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41142562/

相关文章:

ssrs-2008 - 通过 SSRS 参数输入的文本包括字段名称

sql - 如何设置报表服务器实例?

excel - 在 SSRS 中将条件边框导出到 Excel

ssrs-2008 - 如何减小 SSRS PDF 导出大小

reporting-services - SSRS 格式日期时间

python - ('42000', '[42000] [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement. (-3502) (SQLExecDirectW)')

Javascript 日期因月份格式而异

ruby-on-rails - 用 ruby 显示日期

javascript - 无法使用 Javascript 将输入日期与当前日期进行比较

azure - SSRS 与 Azure SQL 报告 - 成本和实现