7 Replies Latest reply: Dec 7, 2015 3:12 PM by Onno van Knotsenburg RSS

    My way of writing CASE WHEN ELSE statement

      Question: How to write the following T-SQL statement in Qlik?

      SELECT

      MyNumber,

      CASE

      WHEN MyNumber = 1 THEN 'One'

      WHEN MyNumber = 2 THEN 'Two'

      ELSE 'Three or more'

      END AS MyText

      FROM ...

       

      Syntax:

      Using PICK and MATCH functions with a value of TRUE to compare with:

       

      PICK (MATCH (-1, Condition1, Condition 2, -1), Result1, Result2, Default Result)

       

      Solution:

      LOAD

      MyNumber,

      PICK ( MATCH (-1, MyNumber = 1, MyNumber = 2, -1), 'One', 'Two', 'Three or more') AS MyText

      FROM ...

       

       

      Please let me know your opinion about it, or if you have a better way for writing that.

      If you want to check, just copy and paste the following:

       

      LOAD *, PICK ( MATCH (-1, MyNumber = 1, MyNumber = 2, -1), 'One','Two','Three or more') AS MyText;

      LOAD * INLINE [MyNumber

      1

      3

      5

      4

      2

      7

      9

      ];