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: 
marcosirotti1950
Contributor II
Contributor II

Left join inside a LOAD in the script

I have two tables defined as such:


ORDERS:
Agent OrdID OrderDate
Agt1    1           2021-05-15
Agt1    2           2022-01-01
Agt2 ...
...
SALE_AGENTS:
Agent DateFrom    DateTo          Dept
Agt1   2021-01-01  2021-05-01  Dept1
Agt1   2021-05-02  2021-12-01  Dept2
Agt1   2021-12-02  2022-05-31  Dept3
Agt2 ...
...


I need to join the 2 tables in a way that for every order of every agent I have the dept in wich he was located at the time of the order. In this case I need:


Agent OrdID OderDate      Dept
Agt1    1           2021-05-15  Dept2
Agt1    2           2022-01-01  Dept3
Agt2 ...
...

The two tables are in different connections, so I cannot make a direct SQL JOIN.

How can I do this in a LOAD statement after the two different SQL SELECT ? Can I use in Qlik Sense a left (or inner) join with a where condition based on data from the two different tables? What would be the correct syntax?

Thank you

Labels (1)
1 Solution

Accepted Solutions
marcosirotti1950
Contributor II
Contributor II
Author

Thanks, the IntervalMatch solution works fine. I just had to add a distint to the last load.

View solution in original post

3 Replies
vinieme12
Champion III
Champion III

As below

ORDERS:
load Agent,OrdID,date(date#(OrderDate,'YYYY-MM-DD')) as OrderDate inline [
Agent,OrdID,OrderDate
Agt1,1,2021-05-15
Agt1,2,2022-01-01
];

Left JOin(ORDERS)
Load
Agent
,Dept
,DateFrom+iterno() as OrderDate
While DateFrom+iterno()<=DateTo
;
load Agent,Dept,date(date#(DateFrom,'YYYY-MM-DD')) as DateFrom , date(date#(DateTo,'YYYY-MM-DD')) as DateTo inline [
Agent,DateFrom,DateTo,Dept
Agt1,2021-01-01,2021-05-20,Dept1
Agt1,2021-05-20,2022-05-31,Dept2
];

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
vinieme12
Champion III
Champion III

you can also use IntervalMatch()

 

https://help.qlik.com/en-US/qlikview/May2022/Subsystems/Client/Content/QV_QlikView/Scripting/ScriptP...

 

 

ORDERS:
load Agent,OrdID,date(date#(OrderDate,'YYYY-MM-DD')) as OrderDate inline [
Agent,OrdID,OrderDate
Agt1,1,2021-05-15
Agt1,2,2022-01-01
];

SALE_AGENTS:
load Agent,Dept,date(date#(DateFrom,'YYYY-MM-DD')) as DateFrom , date(date#(DateTo,'YYYY-MM-DD')) as DateTo inline [
Agent,DateFrom,DateTo,Dept
Agt1,2021-01-01,2021-05-20,Dept1
Agt1,2021-05-20,2022-05-31,Dept2
];

Left Join IntervalMatch ( OrderDate,Agent )
LOAD DateFrom,DateTo,Agent
Resident SALE_AGENTS;
exit script;

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
marcosirotti1950
Contributor II
Contributor II
Author

Thanks, the IntervalMatch solution works fine. I just had to add a distint to the last load.