1

我使用此自定义代码在 SSRS 中设置名为 TermCodes 的参数:

Public Function setTermDates (ByVal academicYear as String) as String
    dim results as String
    dim startYear as String = Mid(academicYear, 3, 2)            'Line 70
    dim endYear as String = Mid(academicYear, 8, 2)

    results = chr(39) & "FS"  & startYear & chr(39) & ", " & chr(39) & "SS" & endYear &  chr(39) & ", " & chr(39) & "US" & endYear & chr(39)

    return results
End Function

@TermCodes 的值为“FS13”、“SS14”、“US14”。我尝试使用此参数的 SQL 是:

select
min(StartDate1) FallStartDate,
min(EndDate1) FallEndDate,
min(StartDate2) SpringStartDate,
min(EndDate2) SpringEndDate,
min(StartDate3) SummerStartDate,
min(EndDate3) SummerEndDate
from    (
    select
        Start_Date, End_Date,
        'StartDate' + cast(row_number() over(order by Start_Date) as char(1)) StartDates,
        'EndDate' + cast(row_number() over(order by Start_Date) as char(1)) EndDates
    from Term
    where Term_Code in (@TermCodes)
    ) t
pivot   (
        max(Start_Date)
        for StartDates in(StartDate1,StartDate2,StartDate3)
        ) sd
pivot   (
        max(End_Date)
        for EndDates in(EndDate1,EndDate2,EndDate3)
        ) ed

问题是 SQL 没有返回任何内容。如果我将此 SQL 键入 SQL Server Management Studio 并将 @TermCodes 替换为上述值,它就可以工作。为什么它在 SSRS 中不起作用?

谢谢!

编辑:我也试过这个来设置我的参数,结果相同:

Public Function setTermDates (ByVal academicYear as String) as String()
dim results(0 to 2) as String
dim startYear as String = Left(academicYear, 4)
dim endYear as String = Right(academicYear, 4)

results(0) = "FS" + startYear
results(1) = "SS" + endYear
results(2) = "US" + endYear

return results
End Function
4

2 回答 2

0

我不相信。这是人为错误。我正在查看原始自定义代码(我放在“编辑”下)并注意到我使用的是全年而不是最后两位数。新代码是:

Public Function setTermDates (ByVal academicYear as String) as String()
    dim results(0 to 2) as String
    dim startYear as String = Mid(academicYear, 3, 2)
    dim endYear as String = Mid(academicYear, 8, 2)    
    results(0) = "FS" + startYear
    results(1) = "SS" + endYear
    results(2) = "US" + endYear

    return results
End Function

我运行了报告,它的工作方式应该是这样。

于 2014-02-21T19:41:37.707 回答
0

不知道为什么它在 SSRS 中不起作用,但您可以尝试将 SQL 代码放入存储过程中,然后将 @TermCodes 作为参数传递给存储过程,然后通过 SSRS 中的数据集调用存储过程。

于 2014-02-21T19:34:44.927 回答