hash.f
hash.f

Reputation: 1

Report field to display correct error message in ssrs

I have a dropdown with parameters Student Name and Student Id. When I select Student Name a textbox appears as below and have the submit button:

enter image description here

On clicking Student ID the report parameter is displayed as below:

enter image description here

For both Student name and student Id am using the dataset StudentDetails. When the report runs if the value for student Name is not found should display message “Student Name not found” and if Student Id is incorrect should display message “Student Id not found”.
On the report I have added a textbox to display the message with the expression as below:

enter image description here

=SWITCH(
        First(Fields!StudentName.Value, "StudentDetails")=""," Student Name not found ",
        First(Fields!StudentId.Value, " StudentDetails ")=""," Student Id not found ")

When incorrect student name is input the message appears correctly, however, for incorrect student id still the same message is displayed “Student Name not found”

Thanks for helping

Upvotes: 0

Views: 285

Answers (1)

Alan Schofield
Alan Schofield

Reputation: 21703

You either need to nest the IIF statements like this

=IIF(
    First(Fields!StudentName.Value, "StudentDetails")="","Student Name not found",
    IIF(
        First(Fields!StudentId.Value, "StudentDetails")="","Student Id not found"
        ,"")) 

or use a SWITCH statement which is usually easier to read.

=SWITCH(
        First(Fields!StudentName.Value, "StudentDetails")="","Student Name not found",
        First(Fields!StudentId.Value, "StudentDetails")="","Student Id not found"
        )

Edit after update from OP

SWITCH will stop at the first expression that is true so if you want to report that both are empty then you will need to add another expression to the SWITCH statement

=SWITCH(
        First(Fields!StudentName.Value, "StudentDetails")="","Student Name not found",
        First(Fields!StudentId.Value, "StudentDetails")="","Student Id not found",
        First(Fields!StudentName.Value, "StudentDetails")="" AND First(Fields!StudentID.Value, "StudentDetails")="","Student Name AND ID not found"
        )

If this does not work then add text boxes to debug each expression, it might be that, for instance StudentID is numeric datatype and therefore you will have to adjust the test to suit (e.g. = Nothing)

Upvotes: 0

Related Questions