Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
ZoharB
Contributor III
Contributor III

Conditional load with Where clause

Hi,

I am trying to load a qvd table with a condition that one of the fields is connected to another table that is already loaded and defines that field availability. Here is an example:

Load Param01, Param02 from Table01 (qvd)
This table is loaded first in the process and it contains two fields.
The field Param01 is a key field that links between Table01 and Table02.
Now I load the data in Table02 but only records where the corresponding field Param02 in Table01 for the record Param01 complies with the condition.

Load Param03, Param04, Param01 from Table02 (qvd)
where Param02<>5

Is this possible?

Thanks

 

Labels (1)
1 Solution

Accepted Solutions
ZoharB
Contributor III
Contributor III
Author

Finally I got the solution, based on your advise 🙂 Thank you so very much

View solution in original post

10 Replies
BrunPierre
Partner - Master
Partner - Master

Try below.

T1:
LOAD Param01,
Param02
FROM Table01 (qvd);

T2:
Load Param03,
Param04,
Param01
FROM Table02 (qvd)
Where Exists(Param01,Param02) and Param02 <> 5;

DROP Table T1;

ZoharB
Contributor III
Contributor III
Author

Thanks, that's a great solution.

ZoharB
Contributor III
Contributor III
Author

Still it doesn't work  😞  Somehow it seems that when I load Table02 the system still doesn't know Table01 although it is loaded first.  Any other suggestion? Or Correction? Maybe I am missing something...Thanks

 

marcus_sommer

It's not quite clear how your condition should work respectively which records should remain? It would be helpful if you elaborate it in more details, for example by providing about 5 (dummy) records of each qvd and which records from them should be kept and removed.

ZoharB
Contributor III
Contributor III
Author

In fact, my goal is to add a field to the table.

Here is an example:

Table A - Hospitals:

Fields: Hospital_name, Hospital_ID, IsGeneral (logical field)

HospA - ID01 - TRUE
HospB - ID02 - FALSE
and so on...

The second Table - People in Hospitals

Fields: Hospital_ID, Person_ID , Age

ID01 - P01 - 23
ID01 - P02 - 39
ID02 - P03 - 45
ID02 - P04 - 72
ID01 - P05 - 81

Actually I want to load the table People in Hospitals where I can add for each record the Hospital name, only if the field ISGENERAL (from the first table, that corresponds to the the Hospital_ID which is the key between the two tables) is TRUE. All the records in the second table where Hospital_ID in the first table is FALSE are not loaded...

This is necessary for further analysis.

Any help would be appreciated.

Thanks,

Zohar.

ZoharB
Contributor III
Contributor III
Author

Intuitively I would do:

Load * from TableA (defining the conditions, as measures)
Load * from TableB where (TableA.Hospital_id=TableB.hospital_ID) and (TableA.IsGeneral=TRUE)

Any suggestions would be highly appreciated. Thanks

 

marcus_sommer

I think I would do something like this:

temp: load true() as IsGeneral autogenerate 1;

first: load ID, IsGeneral from first.qvd (qvd) where exists(IsGeneral);

second: load * from second.qvd (qvd) where exists(ID);

drop tables temp, first;

ZoharB
Contributor III
Contributor III
Author

I still have a problem with the "exists" clause [exists IsGenera].
The following error occurred: 
Unexpected token: 'IsGeneral', expected one of: 'biff', 'dif', 'fix', 'html', 'json', 'kml', 'ooxml', ...

Any idea what I did wrong?

marcus_sommer

It seems that there is any load-statement-ending character of ; is missing and Qlik concatenates multiple statements and couldn't find a valid file-format for a load.