Question

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
Was it helpful?

Solution 2

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.

OTHER TIPS

not sure why it wouldnt work in SSRS but you could try putting you SQL code in a stored procedure and then pass @TermCodes as a parameter to the stored procedure, then call the stored procedure through a dataset in SSRS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top