我用這個自定義代碼在SSRS設置一個參數叫做TermCodes:SSRS:參數通過自定義代碼設置似乎不工作
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