Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Alex2310
Contributor
Contributor

Incremental Load: Insert, update and delete

Hi everyone,

I am currently having problems with the development of the script to carry out an incremental load from a BBDD to a QVD.
I am using the information that Qlik makes available on the topic: Isert, update and delete (https://help.qlik.com/en-US/sense/February2022/Subsystems/Hub/Content/Sense_Hub/LoadData/use-QVD-fil...).

The solution proposed in the help page works for tables that have only one primary key. 

I tried to implement this solution on tables with 2 primary keys or more but I don't get the expected result.
Has anyone implemented a script for incremental loading of tables with two or more primary keys?

My script looks something like this:

Let ThisExecTime = Now( );

QV_Table:

SQL SELECT PrimaryKey1, PrimaryKey2, X, Y FROM DB_TABLE

WHERE ModificationTime >= #$(LastExecTime)#

AND ModificationTime < #$(ThisExecTime)#;

Concatenate

LOAD PrimaryKey1, PrimaryKey2 X, Y FROM File.QVD

WHERE NOT EXISTS(PrimaryKey1) AND NOT EXIST(PrimaryKey2);

 

Inner Join SQL SELECT PrimaryKey1, PrimaryKey2 FROM DB_TABLE;

 

If ScriptErrorCount = 0 then

STORE QV_Table INTO File.QVD;

Let LastExecTime = ThisExecTime;

End If

 

Labels (1)
1 Reply
rubenmarin

Hi, you'll need a unique key, a unique key can be created with a combination of hte different primary keys as:

QV_Table:
LOAD *, PrimaryKey1&'_'&PrimaryKey2 as UniqueKey;
SQL SELECT PrimaryKey1, PrimaryKey2, X, Y FROM DB_TABLE

And check exists as

LOAD PrimaryKey1, PrimaryKey2 X, Y FROM File.QVD
WHERE NOT EXISTS('UniqueKey',PrimaryKey1&'_'&PrimaryKey2);

After this you can do a "DROP Field UniqueKey;"