3 Replies Latest reply: Mar 23, 2016 8:37 AM by Peter Cammaert RSS

    If with one condition and multiple expressions

    Kirsten Zawierucha

      Dear community,


      is there any possibility to create an if-statement with only one condition but multiple expressions?

      I need to load a table with these information in my script.


      Simple exmple:

      if(IsNull(A),B and C)


      If my idea isn't practicable are there any other possibilities to get two results at once using only one condition?




        • Re: If with one condition and multiple expressions
          kushal chawda

          On what condition what you are trying to achieve? can you elaborate a bit more

          • Re: If with one condition and multiple expressions
            Sunny Talwar

            Not sure what you want to see, but may be this:


            If(IsNull(A), B & ' ' & C) as NewCol

            • Re: If with one condition and multiple expressions
              Peter Cammaert

              A resident table (the end result of any script LOAD) can store either one (number or text with corresponding representation) or two values (dual() where string and number don't need to correspond but they do have a very strict relation) in every column cell. The most common (and most simple) method is to store a single expression result in a single cell.


              If your outcome of the IF-true expression can be stored as a single value (either by concatenating B to C, like Sunny suggested, or by simply performing B + C to get a single number) then yes, you can use a single IF function evaluation.


              If not, you'll have to create separate columns and repeat the same IF clause in every column expression. Don't worry, this is common practice.


              If the IF function is too complex to repeat in a maintainable state, store the outcome of the IF function in a temporary Flag field, and use that Flag field in a Preceding LOAD that immediately follows to calculate the different column values, like:



              LOAD IF (Flag = 1, B) AS ColumnB,

                   IF (Flag = 1, C) AS ColumnC,

                   : // other fields

                   ; // Terminate preceding LOAD

              LOAD IF (This and that but not those and omit these while excluding the others and in case of an exception accept everything, 1, 0) AS Flag,

                   : // other fields

              FROM ExternalSourceFile (options);


              That way you'll have to repeat the complex IF clause only once.