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: 
Anonymous
Not applicable

Why won't my incremental load work?

My initial creation of the QVD file works just fine.  But when the ELSE statement gets executed, the QVD then contains zero records.  If I modify one record in the database after the initial creation of the QVD, I can then see, in the execution of the ELSE statement, that the logic is detecting the 1 modified record, but still the QVD is created with zero records.

IF (isnull(QvdCreateTime('KATIE.qvd'))) then // if qvd file doesnt exist
  
   KATIE1_SQL:
    
SQL
      select * from people_T where first_name='Katie';
    
STORE KATIE1_SQL INTO  KATIE.qvd ;
    
Let LastExecTime4 = Now( );

ELSE
     
Let ThisExecTime4 = Now( );
      KATIE2_SQL:
    
SQL 
       select * from people_T where first_name='Katie'
       AND ( LAST_CHANGE_DATE >= to_timestamp('$(LastExecTime4)', 'MM/DD/YYYY HH:MI:SS AM') AND LAST_CHANGE_DATE < to_timestamp('$(ThisExecTime4)',  'MM/DD/YYYY HH:MI:SS AM') ) ; 
      
Concatenate LOAD * FROM KATIE.qvd 
      WHERE NOT EXISTS(ID);
// unique key
     Inner Join SQL select * from people_T where first_name='Katie';

     
If ScriptErrorCount = 0 then
          
STORE KATIE2_SQL INTO KATIE.qvd ;
          
Let LastExecTime4 = ThisExecTime4;
     
EndIf;

ENDIF;


1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

The solution is, in the INNER JOIN statement, I had to change "SELECT *" to "SELECT (ID)"

Complete solution to handle new recs, deleted recs, and updated recs:

IF (isnull(QvdCreateTime('KATIE.qvd'))) then // if qvd file doesnt exist

KATIE1_SQL:
SQL
select * from people_T where first_name='Katie';

STORE KATIE1_SQL INTO  KATIE.qvd ;
Let LastExecTime4 = Now( );

ELSE
Let ThisExecTime4 = Now( );

KATIE2_SQL:
SQL 
select * from people_T where first_name='Katie'
AND ( ( LAST_CHANGE_DATE >= to_timestamp('$(LastExecTime4)', 'MM/DD/YYYY HH:MI:SS AM') AND LAST_CHANGE_DATE < to_timestamp('$(ThisExecTime4)', 'MM/DD/YYYY HH:MI:SS AM') )
OR
CREATE_DATE >= to_timestamp('$(LastExecTime4)', 'MM/DD/YYYY HH:MI:SS AM')
);
Concatenate LOAD * FROM KATIE.qvd (qvd)
WHERE NOT (EXISTS(ID));

INNER JOIN (KATIE2_SQL) SQL select (ID) from people_T where first_name='Katie' ;

If ScriptErrorCount = 0 then
STORE KATIE2_SQL INTO KATIE.qvd ;
Let LastExecTime4 = ThisExecTime4;
EndIf;

ENDIF;

View solution in original post

4 Replies
shraddha_g
Partner - Master III
Partner - Master III

I guess let lastExecTime4 statement after Else is an issue

Anonymous
Not applicable
Author

But I see the following query getting executed:

select * from people_T where first_name='Katie'

       AND ( LAST_CHANGE_DATE >= to_timestamp('$(LastExecTime4)', 'MM/DD/YYYY HH:MI:SS AM') AND LAST_CHANGE_DATE < to_timestamp('$(ThisExecTime4)',  'MM/DD/YYYY HH:MI:SS AM') ) ;

So I don't think the Let lastExecTime4 statement is an issue.

vinieme12
Champion III
Champion III

You are not setting variable value for LastExecTime4 in the <ELSE> part, are you setting this before the if section?

also get rid of the Quotes and try

select * from people_T where first_name='Katie'

       AND ( LAST_CHANGE_DATE >= to_timestamp($(LastExecTime4), 'MM/DD/YYYY HH:MI:SS AM') AND LAST_CHANGE_DATE < to_timestamp($(ThisExecTime4),  'MM/DD/YYYY HH:MI:SS AM') ) ;

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
Anonymous
Not applicable
Author

The solution is, in the INNER JOIN statement, I had to change "SELECT *" to "SELECT (ID)"

Complete solution to handle new recs, deleted recs, and updated recs:

IF (isnull(QvdCreateTime('KATIE.qvd'))) then // if qvd file doesnt exist

KATIE1_SQL:
SQL
select * from people_T where first_name='Katie';

STORE KATIE1_SQL INTO  KATIE.qvd ;
Let LastExecTime4 = Now( );

ELSE
Let ThisExecTime4 = Now( );

KATIE2_SQL:
SQL 
select * from people_T where first_name='Katie'
AND ( ( LAST_CHANGE_DATE >= to_timestamp('$(LastExecTime4)', 'MM/DD/YYYY HH:MI:SS AM') AND LAST_CHANGE_DATE < to_timestamp('$(ThisExecTime4)', 'MM/DD/YYYY HH:MI:SS AM') )
OR
CREATE_DATE >= to_timestamp('$(LastExecTime4)', 'MM/DD/YYYY HH:MI:SS AM')
);
Concatenate LOAD * FROM KATIE.qvd (qvd)
WHERE NOT (EXISTS(ID));

INNER JOIN (KATIE2_SQL) SQL select (ID) from people_T where first_name='Katie' ;

If ScriptErrorCount = 0 then
STORE KATIE2_SQL INTO KATIE.qvd ;
Let LastExecTime4 = ThisExecTime4;
EndIf;

ENDIF;