Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello Community,
My understanding is that, for IF condition, wherever condition is satisfied, it comes out of the IF, but it does not seem like that.
In below, I do not have Bname as column in the table, but the hardcode condition should actually skip the else aprt, but it is not.
test:
LOAD
if('A'='A',Aname,Bname) as TName,
* INLINE [
Aname, Aqty
Angad,2
Singh,3
];
This gives error that Bname column not found.
Thanks,
Angad
No. The error message comes as a result of parsing test(syntax). Even before going to execute your if statement or any other statement in the context of original data load, the QV parser has to check for the valid syntax. And there fails your statement, because when the parser finds Bname , it expects it to be a field which can't be sourced. Hence the error. Therefore, in brief your script fails at parsing and not at if statement execution (it doesn't even go to that phase of execution). Hope this helps comprehend.
Hi,
Of course you'll get this error, because you don't have a definition of Bname in your inline table.
Just add it there and you can leave it empty, error will gone.
Hope this helps.
update: this code will work without errors
LOAD
if('A'='A',Aname,Bname) as TName,
* INLINE [
Aname, Aqty,Bname
Angad,2
Singh,3
];
Andrei
It fails during syntax validation in script, since it didn't find the field Bname.
At runtime, expression 'A'='A' is evaluated and assigns Aname
Hi,
If you use Bname as 'Bname' then it will work and it won't throw any error while loading.
if('A'='A',Aname,'Bname') as TName,
Qlikview throws error as it searches for all fields written in the load script.
Hi
i thin this isn't 100 % correct. There isn't a column with the name 'A', also you don't have a fieldvalue like 'A', so this won't work. Have a look at the example, this gives you an idea how if works:
LOAD
if(Aname='Angad',Aname,Bname) as TName,
* INLINE [
Aname, Aqty,Bname
Angad,2
Singh,3
];
Best regards
Stefan
Thanks Andrei, but in original request I cannot add the dummy column in my qvd. So you mean that the if condition traverses the whole line irrespective of condition in case of using columns. Isnt it?
No. The error message comes as a result of parsing test(syntax). Even before going to execute your if statement or any other statement in the context of original data load, the QV parser has to check for the valid syntax. And there fails your statement, because when the parser finds Bname , it expects it to be a field which can't be sourced. Hence the error. Therefore, in brief your script fails at parsing and not at if statement execution (it doesn't even go to that phase of execution). Hope this helps comprehend.
Its failed on Syntax check, Since there is no field called Bname
You could do it by using variable instead.
LET vFieldAB = If('A'='A','Aname','Bname');
and use the variable in LOAD statement like below
test:
LOAD $(vFieldAB) as TName, * INLINE [
Aname, Aqty
Angad,2
Singh,3
];
Use something like below
test:
LOAD
if('A'='A',Aname,Null()) as TName,
* INLINE [
Aname, Aqty
Angad,2
Singh,3
];
Set ErrorMode = 0 ;