Search code examples
sql-serverreporting-servicessql-server-data-tools

Combining IIF statements in ssrs


I'm trying to combine the following IIF statements in SSRS and cannot seem to get the code correct to run. Can anyone help?

=Iif(IsNothing(Fields!Description.Value) and fields!CallFlag.Value = "1" , "New Record to Dial", Fields!Description.Value, Iif(IsNothing(Fields!Description.Value) and fields!CallFlag.Value = "0" , "Do Not Call", Fields!Description.Value, Iif(IsNothing(Fields!Description.Value) and isnothing(fields!CallFlag.Value), "Load Reject", Fields!Description.Value)


Solution

  • The IIF statement reads IIF(boolean, TRUE-value, FALSE-value). In your case you mean: if callflag=1 then "New Record" else if callflag=2 then.......

    That would lead to:

    =Iif(IsNothing(Fields!Description.Value) and fields!CallFlag.Value = "1" ,
      "New Record to Dial", 
      Iif(IsNothing(Fields!Description.Value) and fields!CallFlag.Value = "0" ,
        "Do Not Call", 
        Iif(IsNothing(Fields!Description.Value) and isnothing(fields!CallFlag.Value),  
          "Load Reject", 
          Fields!Description.Value
        )
      )
    )
    

    If you reconfigure that you get:

    =Iif(IsNothing(Fields!Description.Value) and fields!CallFlag.Value = "1" ,
      "New Record to Dial", 
      Iif(IsNothing(Fields!Description.Value) 
        iif(isnothing(fields!CallFlag.Value), "Load Reject",
          Iif(fields!CallFlag.Value = "0" ,   "Do Not Call", 
            Iif(fields!CallFlag.Value = "1" ,   "New Record to Dial", "Error on CallFlag Value")
          )
        )
     , Fields!Description.Value)
    

    Or even better: if you use SQL-server as your tag indicates, use the CASE command... CASE command in SQL