Question

I am facing very simple issue but not getting solution over it. I have textbox in my ssrs report, I am passing value "1;prashant" or null to it. Now, if I pass value "1;prashant" to textbox then textbox should show only "prashant" and If I am passing nothing then it should be blank.

I have tried following IIF condition:
=IIF(IsNothing(FieldS!WIAPPORVER.Value),"",Split(Fields!WIAPPORVER.Value,"#")(1).ToString())

But, I above code is giving an error ["#error" shows in textbox] if I am passing blank value.

Please let me know, where I am wrong in this. Thanks

Was it helpful?

Solution 3

You are relying on the IIf expression short circuiting, but SSRS IIf expressions do not short circuit - the expression will try and work out Split(Fields!WIAPPORVER.Value,"#")(1).ToString() for all rows and fail when this value doesn't exist.

You can get this going by using text expressions, which don't get this error.

With test data:

enter image description here

And a simple table:

enter image description here

I have added columns with both your existing expression and a new expression:

=Right(Fields!WIAPPORVER.Value, Len(Fields!WIAPPORVER.Value) - InStr(Fields!WIAPPORVER.Value, "#"))

This new expression works for NULL values, empty strings and strings with no delimiter present:

enter image description here

OTHER TIPS

There are probably better ways of doing this, but this is what my head came up with at the time:

=IIF(
    IsNothing(Fields!WIAPPROVER.Value)
    ,""
    ,Right(Fields!WIAPPROVER.Value,Len(Fields!WIAPPROVER.Value) -InStr(Fields!WIAPPROVER.Value,";"))
)

I believe SSRS is trying to compute everything in the report at runtime, so in your case it is still trying to fetch index 1 from an array even though there is nothing in it and it crashes.

Edit: Changed parameters to Fields. I created a parameter to remake the issue at my side.

Just get the split out of the iif. Then in your iif, if field is nothing create a string that when split will return ""

=Split(IIF(IsNothing(FieldS!WIAPPORVER.Value),"#", Fields!WIAPPORVER.Value),"#")(1)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top