Check if Value is NULL
Hi, I have a question about one task in reporting services. I have a field with NULL value and when render it it returns #Error. I want to get some like this: =First(IIF(IsNothing(Fields!pytanie7.Value),"", IIF(CStr(Fields!pytanie7.Value).Contains("1"), "X", "")), "DataSet1") So, when Field have NULL it should set "" in textbox, but when it's not it should check i this field contains "1", if yes it should set "X" otherside "". Expression which I right above is not working, it returns #Error ;/ Thanx for reply.
January 12th, 2011 7:50am

Hi IIF evaluates both the true and false expression. The Contains part in the condition does not like evaluating any NULL values and thus gives error. Therefore add an empty string before the Cstr to ensure it does not pass a null when the Contains part is evaluated. =First(IIF(IsNothing(Fields!pytanie7.Value),"", IIF("" & CStr(Fields!pytanie7.Value)).Contains("1"), "X", "")), "DataSet1") Hope this helps Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful. BH
Free Windows Admin Tool Kit Click here and download it now
January 12th, 2011 9:15am

Hmm.. It doesn't work ;/ still in textbox appears #Error Maybe other solution ? Thx!
January 12th, 2011 9:39am

In the SQL test for NULL and substitute a blank. When you get to the report it has a value or is blank.
Free Windows Admin Tool Kit Click here and download it now
January 12th, 2011 6:38pm

Is any idea to solve this problem ? I tried many solutions but cant find this right ;/
January 12th, 2011 6:42pm

Hi, As BH posted, the IIf function always evaluates expressions in both the true part and false part even though only one of them returns. In other words, the expression CStr(Fields!pytanie7.Value).Contains("1") is still executed when Fields!pytanie7.Value is null, and generates the error message. In order to avoid that null value is passed to the CStr function, we need to change the expression to =IIF( IsNothing(Fields!pytanie7.Value) or not CStr(IIf(IsNothing(Fields!pytanie7.Value),"",Fields!pytanie7.Value)).Contains("1"), "","X") As a result, the expression above will be executed successfully in any rate. Thanks, Tony Chain Tony Chain [MSFT] MSDN Community Support | Feedback to us Get or Request Code Sample from Microsoft Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Free Windows Admin Tool Kit Click here and download it now
January 16th, 2011 12:01am

Hi, As BH posted, the IIf function always evaluates expressions in both the true part and false part even though only one of them returns. In other words, the expression CStr(Fields!pytanie7.Value).Contains("1") is still executed when Fields!pytanie7.Value is null, and generates the error message. In order to avoid that null value is passed to the CStr function, we need to change the expression to =IIF( IsNothing(Fields!pytanie7.Value) or not CStr(IIf(IsNothing(Fields!pytanie7.Value),"",Fields!pytanie7.Value)).Contains("1"), "","X") As a result, the expression above will be executed successfully in any rate. Thanks, Tony Chain Tony Chain [MSFT] MSDN Community Support | Feedback to us Get or Request Code Sample from Microsoft Please remember to mark the replies as answers if they help and unmark them if they provide no help.
January 16th, 2011 12:01am

Hi, Try =IIF(IsNothing(Fields!pytanie7.Value),"", IIF(CStr(Fields!pytanie7.Value).Contains("1"), "X", "")) or =IIF(IsNothing(First(Fields!pytanie7.Value, "DataSet1")),"", IIF(CStr(First(Fields!pytanie7.Value, "DataSet1")).Contains("1"), "X", "")) If above two desont work. try Breaking the your syntax into two different values and apply in two different text boxes and check what O/P you get, maybe something fishy. Hope it works. Regards, PS
Free Windows Admin Tool Kit Click here and download it now
January 16th, 2011 12:07am

Hi, Try =IIF(IsNothing(Fields!pytanie7.Value),"", IIF(CStr(Fields!pytanie7.Value).Contains("1"), "X", "")) or =IIF(IsNothing(First(Fields!pytanie7.Value, "DataSet1")),"", IIF(CStr(First(Fields!pytanie7.Value, "DataSet1")).Contains("1"), "X", "")) If above two desont work. try Breaking the your syntax into two different values and apply in two different text boxes and check what O/P you get, maybe something fishy. Hope it works. Regards, PS
January 16th, 2011 12:07am

Hi, Thank you Tony for your help ! It's working great :) Kamil Bo
Free Windows Admin Tool Kit Click here and download it now
January 16th, 2011 9:29am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics