I use this custom code to set a parameter called TermCodes in 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
The value of @TermCodes is 'FS13', 'SS14', 'US14'. The SQL I'm trying to use this parameter with is:
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
The problem is that the SQL is not returning anything. If I type this SQL into SQL Server Management Studio and replace the @TermCodes with the aforementioned value, it works. Why does it not work in SSRS?
Thanks!
Edit: I also have tried this to set my parameter with the same result:
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
不知道为什么它不能在SSRS中工作,但是您可以尝试将SQL代码放入存储过程中,然后将@TermCodes作为参数传递给存储过程,然后通过SSRS中的数据集调用存储过程。
I don't believe it. It was human error. I was looking over the original custom code (that I put under "Edit") and noticed that I was using the whole year and not the last two digits. The new code is:
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
I ran the report and it works like it should.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.