Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Can IF or SWITCH Statement be used inside a LOAD Statement?

Is it possible to use an IF or SWITCH Statement inside a LOAD Statement?

e.g.

Table2:

LOAD DISTINCT Product
, IF Product = 'TRAKTOR' THEN 2 ELSE 1 END IF as Division

RESIDENT Table1;

How is the correct syntax to analyse the value of field A inside the LOAD statement, and create, depending on the content of value A, a new field B ?

Thanks for any help!

TB

1 Solution

Accepted Solutions
Not applicable
Author

Yes !

You can use IF but IF is a FUNCTION not a statement as you think.

Use it like this :

IF (Product = 'TRAKTOR' ,2 ,1) as Division

Got it ?

As for SWITCH there is no such statement AFAIK. I use this kind of construction for that :

,IF(AGE <= 10,'* - INVALID DATE ' ,
IF(AGE > 10 AND AGE <= 19,'A - LESS THAN 20 YEARS',
IF(AGE > 19 AND AGE <= 25,'B - 20 TO 25 YEARS' ,
IF(AGE > 25 AND AGE <= 30,'C - 26 TO 30 YEARS' ,'D - ABOVE 30 YEARS')))) AS FAIXAET_DER_VSCAD

Sometimes I also like to use the PICK function :

PICK(CORRAC_VSCAD,'WHITE',BLACK',YELLOW','PARDA','INDIAN') AS CORRAC_DER_VSCAD

Hope that helps !

View solution in original post

4 Replies
Not applicable
Author

Yes !

You can use IF but IF is a FUNCTION not a statement as you think.

Use it like this :

IF (Product = 'TRAKTOR' ,2 ,1) as Division

Got it ?

As for SWITCH there is no such statement AFAIK. I use this kind of construction for that :

,IF(AGE <= 10,'* - INVALID DATE ' ,
IF(AGE > 10 AND AGE <= 19,'A - LESS THAN 20 YEARS',
IF(AGE > 19 AND AGE <= 25,'B - 20 TO 25 YEARS' ,
IF(AGE > 25 AND AGE <= 30,'C - 26 TO 30 YEARS' ,'D - ABOVE 30 YEARS')))) AS FAIXAET_DER_VSCAD

Sometimes I also like to use the PICK function :

PICK(CORRAC_VSCAD,'WHITE',BLACK',YELLOW','PARDA','INDIAN') AS CORRAC_DER_VSCAD

Hope that helps !

Not applicable
Author

Yes, thats it. Thanks a lot.

TB

Miguel_Angel_Baeyens

Sorry, wrong post. This post may be deleted.

Not applicable
Author

You can use IF in this way:

if a=1 then

load * from abc.csv;

sql select e, f, g from tab1;

end if