Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
virilo_tejedor
Creator
Creator

Can't use a constant on IF stement on a load script

Hi,

I'd like to load data from a database, and create a new field RESULT based on this condition:

  - If STATUS is 3, RESULT contains value of "ERROR_DESCRIPTION" for this row

  - Else, RESULT cotains the constant value "Ok."  

The following code produces an error during the data load, because QlikSense expects "Ok." to be a column name.

LOAD ID as ID_REQUEST,

    .. // lots of columns

    ERROR_DESCRIPTION,

    STATUS,

    If(STATUS  = 3, "STATUS", "OK.") as RESULT;

SQL SELECT ID,

    "ID",

    "REQUEST_DATE",

    ...

    ERROR_DESCRIPTION,

    STATUS,

   

FROM MYDB.REQUESTS;

I tryed the next alternatives, without success:

    - If(STATUS  = 3, "STATUS", Text("OK.")) as RESULT;

   

    - let vOkMessage = "Ok.";

      If(STATUS  = 3, "STATUS", $(vOkMessage)) as RESULT;

     

    -  If(STATUS  = 3, "STATUS", "OK_MESSAGE") as RESULT;

      SQL SELECT ID,

        "Ok." as "OK_MESSAGE", 

        ...  

      FROM MYDB.REQUESTS;

How could I choose between a column value or a constant depending on "STATUS"?

Thanks in advance.

Best regards,

Virilo

1 Solution

Accepted Solutions
sunny_talwar

Try with single quotes around the constant instead of double quotes

LOAD ID as ID_REQUEST,

    .. // lots of columns

    ERROR_DESCRIPTION,

    STATUS,

    If(STATUS  = 3, "STATUS", 'OK.') as RESULT;

SQL SELECT ID,

    "ID",

    "REQUEST_DATE",

    ...

    ERROR_DESCRIPTION,

    STATUS,

 

FROM MYDB.REQUESTS;

View solution in original post

2 Replies
sunny_talwar

Try with single quotes around the constant instead of double quotes

LOAD ID as ID_REQUEST,

    .. // lots of columns

    ERROR_DESCRIPTION,

    STATUS,

    If(STATUS  = 3, "STATUS", 'OK.') as RESULT;

SQL SELECT ID,

    "ID",

    "REQUEST_DATE",

    ...

    ERROR_DESCRIPTION,

    STATUS,

 

FROM MYDB.REQUESTS;

virilo_tejedor
Creator
Creator
Author

Thanks a lot!