SSRS-将表达式与“ If”语句和多个参数值一起使用

时间:2018-08-27 20:20:58

标签: vb.net if-statement reporting-services switch-statement ssrs-2016

因此,我试图为带有4个用户参数字段的SSRS中的报告设置一些动态文本,但我一直遇到相同的错误。我对SSRS和Visual Basic还是很陌生,因此很难理解该错误消息。

System.Web.Services.Protocols.SoapException: The Value expression for the textrun 
‘Textbox2.Paragraphs[2].TextRuns[1]’ contains an error: [BC33104] 'If' operator
requires either two or three operands.

4个参数字段是beginYear,beginMonth,endYear和endMonth。以下是表达式中的代码:

If (bYear = eYear) And (bMonth = 1) And (eMonth = 3)
"3rd Quarter January - March " & eYear

ElseIf  (bYear = eYear) And (bMonth = 4) And (eMonth = 6)
"4th Quarter April - June " & eYear

ElseIf  (bYear = eYear) And (bMonth = 7) And (eMonth = 9)
"1st Quarter July - September " & eYear

ElseIf  (bYear = eYear) And (bMonth = 10) And (eMonth = 12)
"2nd Quarter October - December " & eYear

ElseIf  (bYear = eYear) And (bMonth = 1) And (eMonth = 12)
"Calendar Year " & eYear

ElseIf  (bYear = eYear) And (bMonth = eMonth)
eYear & " " & eMonth 

ElseIf  (((Convert.toInt32(bYear)) = (Convert.toInt32(eYear)) - 1) And (((Convert.toInt32(eYear)) = (Convert.toInt32(bYear)) + 1) And (bMonth = 7) And (eMonth = 6)
"Fiscal Year " & bYear & "-" & eYear

Else
             bMonth & " " & bYear & "-" & eMonth & " " & eYear
End If

因此,如果我从报告中选择了以下参数(在month参数中,我为月份分配了数值):

-Begin Year=2018
-Begin Month=April
-End Year=2018
-End Month=June

我应该在报告的文本框中看到以下表达式=>“ 2018年4月4日-6月”

1 个答案:

答案 0 :(得分:0)

这不是SSRS中If的格式。见下文:

=Iif(Parameters!yourParameter.Value = Parameters!yourAnotherParameter.Value, "value if true", "value if false")

对于您的情况,应使用Switch

=Switch(Parameters!yourParameter.Value = Parameters!yourAnotherParameter.Value 
        AndAlso Parameters!yourParameter.Value = "something else"
        AndAlso Parameters!yourParameter.Value = "again something else", "desired output if all condition are met", 
        Parameters!yourNextParameter.Value = Parameters!yourNextAnotherParameter, "desired output if this condition is met")