The Setup
I have an expression that converts all caps values to proper case. Some of the values have an extra bit preceded by a hyphen, I want everything before that. Sadly a LEFT(INStr
expression errors on instances without a hyphen in.
=IIF(
INstr(Fields!Introducer_Title.Value, "-") = 0,
StrConv(Fields!Introducer_Title.Value,vbStrConv.ProperCase),
"nope"
)
The above works just fine: if there is no hyphen then the string is converted to proper case, otherwise it just says nope.
The Problem
=IIF(
INstr(Fields!Introducer_Title.Value, "-") = 0,
StrConv(Fields!Introducer_Title.Value,vbStrConv.ProperCase),
Left(StrConv(Fields!Introducer_Title.Value, VbStrConv.ProperCase), INstr(StrConv(Fields!Introducer_Title.Value, VbStrConv.ProperCase), "-")-1)
)
The above works in so far as that if there is a hyphen in the value it returns the text before it in proper case, but now the values without hyphens error. The logic hasn’t changed.
It's as if instead of going IIF(A=TRUE,This,That) is somehow converted to always do That when I replace the Otherwise "nope" with a nested expression.
The error is just #Error, no other information.
Am I missing something obvious? I have a feeling this is some quirk of SSRS.
Updates
This is getting stranger the more I look into it:
- Wrapping the function in an
ISERROR
is creating an error on the bad rows, rather than returningtrue
. - Using an
InStrRev
function is returning the same value as anInStr
function even though the position of the hyphen in the first row is not in the middle (I checked the values in Excel)