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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

String variable in script

Hello,

I am trying to define a string variable and use it in a script. It works fine if I create the variable in the Variable Viewer:

Variable name = Status

Value = 'OK'

LOAD

    INFO,

    if(INFO=$(Status), $(Status), 'KO') AS INFO2

FROM file.xlsx [...];

But when I try to declare the variable in the script it fails:

SET Status='OK'; //I also tried SET Status="OK";

LOAD

    INFO,

    if(INFO=$(Status), $(Status), 'KO') AS INFO2

FROM file.xlsx [...];

Error:

Field not found <OK>

if(Status=OK,OK,'') AS INFO2

Quotes around 'OK' are removed so string OK is seen as a field name instead of a string value. If you look at the variable in the Variable Viewer:

Variable name = Status

Value = OK <------- quotes are missing

How to keep the quotes to make sure the variable is interpreted as a string and not a field name?

Labels (1)
1 Solution

Accepted Solutions
Not applicable
Author

Hi,

try with this:

LOAD

    INFO,

    if(INFO='$(Status)', '$(Status)', 'KO') AS INFO2

FROM file.xlsx [...];

regards

View solution in original post

3 Replies
Not applicable
Author

Hi,

try with this:

LOAD

    INFO,

    if(INFO='$(Status)', '$(Status)', 'KO') AS INFO2

FROM file.xlsx [...];

regards

vijay_iitkgp
Partner - Specialist
Partner - Specialist

Hi,

Put your variable under quotes:

if(INFO='$(Status)', '$(Status)', 'KO') AS INFO2

Not applicable
Author

It works like a charm! (I indeed got misleaded by the syntax editor coloring)

Thank you very much!