2014-02-21 41 views
1

我用這個自定義代碼在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 

回答

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 

我跑了報告,它的工作原理就像它應該。

0

不知道爲什麼它wouldnt在SSRS的工作,但你可以嘗試把你在存儲過程中的SQL代碼,然後通過@TermCodes作爲存儲過程的參數,然後通過SSRS中的數據集調用存儲過程。