我使用此自定义代码在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
答案 0 :(得分:0)
不确定为什么它在SSRS中不起作用,但您可以尝试将SQL代码放在存储过程中,然后将@TermCodes作为参数传递给存储过程,然后通过SSRS中的数据集调用存储过程。
答案 1 :(得分: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
我运行了报告,它的工作原理应该如此。