Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Read about the latest Qlik Community enhancements on the Community News blog!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Issue with If in load script at column level

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

1 Solution

Accepted Solutions
tresesco
MVP
MVP

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.

View solution in original post

9 Replies
crusader_
Partner
Partner

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

anbu1984
Master III
Master III

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

Not applicable
Author

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.

s_kunte23
Creator III
Creator III

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

Not applicable
Author

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?

tresesco
MVP
MVP

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.

View solution in original post

CELAMBARASAN
Partner
Partner

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

];

MK_QSL
MVP
MVP

Use something like below

test:

LOAD

if('A'='A',Aname,Null()) as TName,

* INLINE [

Aname, Aqty

Angad,2

Singh,3

];

er_mohit
Master II
Master II

Set ErrorMode = 0 ;