简体   繁体   中英

Nested iif statements in SSRS

I am attempting to write a nested iif statement in SSRS that will convert the varchar values that are numbers(isnumeric) to integer and leave the text as is. I also want to be sure if the value in the cell is "0" it will return a blank or "". Please see the code I am using below. Any insights as to why the non-numeric text is showing as #Error would be greatly appreciated. Thanks!

=iif(
Fields!O1_Parent_Line_Item_ID.Value is "0", "", iif(ISNUMERIC(Fields!O1_Parent_Line_Item_ID.Value), CInt(Fields!O1_Parent_Line_Item_ID.Value), Fields!O1_Parent_Line_Item_ID.Value))

Use a SWITCH statement instead of nested IIF s and test for non numeric first. SWITCH statements stop at the first expression that returns true.

=SWITCH (
    ISNUMERIC((Fields!O1_Parent_Line_Item_ID.Value), CInt(Fields!O1_Parent_Line_Item_ID.Value), 
    Fields!O1_Parent_Line_Item_ID.Value = "0", ""
    True, Fields!O1_Parent_Line_Item_ID.Value
    )

The above statement will test each expression in turn until it finds one that returns true. So if it's numeric, convert to int . If it's "0" return and empty string. If both those return false then the last expression will always return true so you will get you original value.

Note that 0 numeric values will return 0 not "" as they are obviously numeric so the first expression will catch it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM