This is a migrated thread and some comments may be shown as answers.

Filtering on a nullable parameter

2 Answers 366 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 04 Oct 2011, 10:34 PM
I have the filters for my textbox set up this way:

             =Fields.LeaseType         =      =Parameters.DealTypeId.Value
AND      =Fields.MedicalEntityId     =      =Parameters.MedicalEntity.Value

However, MedicalEntityId is a nullable value in the database, and I just want it to display the records where the MedicalEntityId is null when I don't specify a value for it in the dropdown list under the preview tab.

When I add in the second parameter and I try to run the report, I get this error: "Object cannot be cast from DBNull to other types." 

My initial thought was to change the second filter expression this way :

AND     =Fields.MedicalEntityId     =       =IsNull(Parameters.MedicalEntity.Value, Null)

but I get the same result with that. What am I missing?

2 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 05 Oct 2011, 05:42 PM
Hello Nick,

In order to display all of the MedicalEntityId records, when Parameters.MedicalEntity.Value is null our suggestion is to use the following expression:
 Expression  Operator  Value
=IIF(Fields.MedicalEntityId is null, "true", Fields.MedicalEntityId)   = =IIF(Parameters.MedicalEntity.Value is null, IsNull(Fields.MedicalEntityId,"true"), Parameters.MedicalEntity.Value) 

Just to note that if MedicalEntityId is of type integer, you have to use an integer for default value.

All the best,
Peter
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Nick
Top achievements
Rank 1
answered on 06 Oct 2011, 04:33 PM
Hi Peter,

A small variation of that expression worked for me: 

=IIF(Fields.MedicalEntityId is Null, 1, Fields.MedicalEntityId)
=
=IIF(Parameters.MedicalEntityId.Value is Null, IIF(Fields.MedicalEntityId is Null, 1, 0), Parameters.MedicalEntityId.Value)

Like you mentioned, I just had to change the "true" to integer values to make it work, and I had to change up the "Value" part a little bit so that it wouldn't return records that are associated with a medical entity when no medical entity is specified as a parameter.

But it works! Thank you, and my apologies for posting this question through two channels; I saw my post sliding down in the forum and thought it was in danger of being forgotten, but that won't happen again.
Tags
General Discussions
Asked by
Nick
Top achievements
Rank 1
Answers by
Peter
Telerik team
Nick
Top achievements
Rank 1
Share this question
or