Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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 !
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 !
Yes, thats it. Thanks a lot.
TB
Sorry, wrong post. This post may be deleted.
You can use IF in this way:
if a=1 then
load * from abc.csv;
sql select e, f, g from tab1;
end if