=IIF Statement

  • I am just trying to do some maths on my report and thought I would use the IIF statement to do the work. The problem I have is that all of the searches I have done on the net seem to revolve around finding values that = rather than not equal. Obviously if this was a number I was searching on I could use;

    =IIF(ReportItems!DataRow2_Floorspace_Total.Value<>0,(ReportItems!DataRow2_Floorspace_Occupied.Value)/(ReportItems!DataRow2_Floorspace_Total.Value),0)

    but what is the SSRS expression equivelant of <> when it comes to searching for something that is <> "Vacant" as an example.

    Using <> just throws up an error which I guess I would expect as it is not a numerical value I am searching for.

    Regards

  • You CAN compare text strings with the IIF Statement, even . You just have to make sure you are comparing a String value to a String value.

  • Instead of using 0, trying using "Nothing", like:

    =IIF(ReportItems!DataRow2_Floorspace_Total.Value <> Nothig, .....

    Hope this will help.

  • Thank you for the information

    Regards

     

  • The IIF function is really nice for testing values before a computation.  It works much like an If/Then/Else statement in Visual Basic.  The first parameter can be any expression that evaluates to a boolean.  You have access to most of the Visual Basic expression syntax to do this test.  The second is what value you want when the boolean condition is true, and the last is what value you want when its false.  You can even nest IIFs to get the values you want.

    Say you wanted to compute a percentage based on FieldA and FieldB but sometimes FieldB can be null or zero.  In Visual Basic you might say something like:

    If FieldB is Nothing then

        Percent = 0

    else

        if FieldB = 0 then

            Percent = 0

        else

            Percent = FieldA / FieldB

        end if

    end if

    Which would look like:

    = IIF(FieldB is nothing), 0, IIF(FieldB = 0), 0, FieldA/FieldB)

  • hmmm doesn't microsoft use =! (or is it != ) in .net? can't say i've had this problem, but i tend to do my work in the SQL query as i understand the SQL functions better.

    I've found help for .net functions in VS 2003 to leave a bit to be desired. Hopefully VS 2005 will be better...


    Kindest Regards,

    Martin

  • Good Morning,

    I eneded up using this as the expression which works fine;

    =IIF(Not(Fields!unittype.value = "Car Parking") AND Not(Fields!unitstatus.value = "Vacant"),1,0)

    Thank you for all your assistance

    Regards

     

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply