Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

IF-statement within Load

Hi All,
I would like to write an IF-statement within the Load.
If the variable (vDB) is set to the value 1, I want to Load the Field named “Field 1” as “New Field Name”. If vDB is ‘2’, I want to Load the Field named “Field 2” as “New Field Name”.
I tried this:
let vDB = 1;  //vDB = 2;

Table:
Load
if ($(vDB) = 1, "Field 1", "Field 2")as "New Field Name";
SQL Select *
From sourcetable;
…but it doesn’t work correctly.
If I set vDB =1 it works correct and QlikView loads “Field 1” as “New Field Name”.
If I set vDB = 2 QlikView causes an Error.
The Error message is: “Field not found “Field 1”…
Is it possible in QlikView at all?
Please help me out.
Thanks a lot.
4 Replies
Sokkorn
Master
Master

Hi Daniel1990,

Try this

let vDB = 1;  //vDB = 2;

Table:
Load
 
if ($(vDB) = 1, 'Field 1', 'Field 2')as "New Field Name";
SQL Select *
From sourcetable;

Regards,

Sokkorn Cheav

luciancotea
Specialist
Specialist

If you want to load a filed NAMED "Field 1", and not loading the value "Field 1", then:

let vDB = 1;  //vDB = 2;

Table:
Load
if ($(vDB) = 1, [Field 1], [Field 2]) as [New Field Name];
SQL Select *
From sourcetable;

Not applicable
Author

Hi,

thanks for the fast answers.

Unfortunately it does not solve the problem.

Maybe i have to add a few supplementations:

With the variable vDB I will load data from two different databases. If it is set to 1 Load from database 1, if it is set to 2 load from database 2.

Now the problem is, that in the table in database 1 the field, i want to load, is named "Field 1" and in database 2 it is named "Field 2".  There is no "Field 1" in database 2 and no "Field 2" in Database 1.

If I try this:

let vDB = 2;  //load from database 2 where "Field 1" not exists

if ($(vDB) = 1, [Field 1], [Field 2]) as [New Field Name];  //now i want to load "Field 2" from the Else-statement

it is the same error. Field not exists. "Field 1"

I would think it is impossible in QlikView.

Thanks a lot for your help.

regards,

Daniel1990

luciancotea
Specialist
Specialist

If the fields are in different databases, then you have to bring them first toghether inside QlikView. After that you can use your IF().

// bring the first field

ODBC Connect to Database1;

Temp_Table:

SELECT [key], [Field 1]

FROM Table1;

// bring the second field

ODBC Connect to Database2;

JOIN (Temp_Table)

SELECT [key], [Field 2]

FROM Table2;

let vDB = 2;  //load from database 2 where "Field 1" not exists

LOAD [key],

            if ($(vDB) = 1, [Field 1], [Field 2]) as [New Field Name]

RESIDENT Temp_Table;