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.

有帮助吗?

解决方案

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)

其他提示

What you did on the first line is correct, and I suspect you are getting a middle name from the database that is a space; which is why it appears double.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top