Luca Rusin
Luca Rusin

Reputation: 81

IIF construct not resolving the correct way (SSRS)

I've got a problem with this piece of code inside a parameter in SSRS2012.

=IIF(InStr(Parameters!P1.Value,"@")=0,
"missing @", 
Left(Parameters!P1.Value(InStr(Parameters!P1.Value,"@")-1)))

My aim is to check if the parameter P1 contains a "@" if it doesn't i will print "missing @" otherwise i want to remove from that parameter what's after the "@" ("@" inculded).

example:
P1 = 123456 --> print "missing @"
P1 = 123@56 --> print 123

The problem is that SSRS drops the error: "Argument 'length' must be greater or equal to zero" when i insert a value with no "@". (when i insert a value with an "@" it goes all well)

It seems like the IIF resolves the 2 expressions first (rather than one is true or false) and after that it gives you the correct one based on the evaluation of the first condition.

Looking for some help. Thanks!

Upvotes: 0

Views: 304

Answers (1)

Kostya
Kostya

Reputation: 1605

it is a weird bug, here is one solution

=replace(replace(IIF(InStr(Fields!P1.Value,"@")<> 0,
left(Fields!P1.Value,InStr(Fields!P1.Value,"@")),"missing"),"@",""),"missing","missing @")

Upvotes: 1

Related Questions