Q:

SSRS Report: Extra space between fields when a field is null

I have a report that displays a member name in the format of: prefix, first, middle, last, suffix. The report code looks like this: [name_prefix] [name_first] [name_middle] [name_last] [name_suffix]
Each field entry has a single space between and works great when the member has a middle name, but when the middle name is Null two spaces render between the first and last names. I tried solving the issue with an expression that looks like this:
=IIF(IsNothing(Fields!name_middle.Value),"",Fields!name_middle.Value & " ")

I also adjusted the spacing to look like this: [name_first] [name_middle][name_last] with no space between the middle and last name field. My hope was that if there was a middle name there would be spaces between the names and when the middle name was null then only one space between first and last name. When there is a middle name it renders correctly but if the middle name is Null there is still an extra space. So I tried another method with no spaces between the fields that looks like this:
=IIF(IsNothing(Fields!name_middle.Value)," "," " & Fields!name_middle.Value & " ")

Again same issue, works fine where there is a middle name but two spaces when there is not. I have considered concatenating the entire member name but I think I will have the same result. The same report done with Crystal Reports uses the first method and it works without issue. Thank you in advance.

A:

Depending on the underlying data source, it is possible that where there is no middle name it is being treated as an empty string, rather than a null.
I suggest amending the expression to be like the following:
=IIF(IsNothing(Fields!name_middle.Value) OR Len(Fields!name_middle.Value) < 1,
     "",Fields!name_middle.Value & " ")

A good test to find the length of the string within a field is:
=Len(Fields!fieldName.Value)

