Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
493 views
in Technique[技术] by (71.8m points)

reporting services - IsNothing error

I have the following error which I can't understand from my expression.

=IIF(IsNothing(Fields!month.Value),"6mr",LEFT(Format(DateValue(MonthName(Right(Fields!month.Value, 2))
 + "," + 
 Left(Fields!month.Value,4)), "Y"),3) + " '" + RIGHT(Format(DateValue(MonthName(Right(Fields!month.Value, 2))
 + "," + 
 Left(Fields!month.Value,4)), "Y"),2))

This works perfectly without the IsNothing element.

I have tested the IsNothing element and that works in the following case:

=IIF(IsNothing(Fields!month.Value),"6mr",0).

Help to correct much appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You are experiencing this "issue" because Reporting Services evaluates both sides of the Iif.

This is not really an issue, it is by design, see this technet article for more details:

Yes , By design the SSRS evaluates both True & False statements even though the condition is not satisfied and through error if something is not right.

Now, to get your expression working, you have to consider that Fields!month.Value could be nothing even in the false part of your expression.

So in your expression, you could just replace

Fields!month.Value

by

Iif(IsNothing(Fields!month.Value), "1", Fields!month.Value)

Here is an expression with this fix:

=Iif(IsNothing(Fields!month.Value),"6mr",Left(Format(DateValue(MonthName(Right(Iif(IsNothing(Fields!month.Value), "1", Fields!month.Value), 2))
 + "," + 
 Left(Iif(IsNothing(Fields!month.Value), "1", Fields!month.Value),4)), "Y"),3) + " '" + Right(Format(DateValue(MonthName(Right(Iif(IsNothing(Fields!month.Value), "1", Fields!month.Value), 2))
 + "," + 
 Left(Iif(IsNothing(Fields!month.Value), "1", Fields!month.Value),4)), "Y"),2))

You could also create a custom function or use a variable if you want to reduce the expression length.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...