Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

IF else condition while scripting Incremental Load

Hi Guys,

I need your help in completing my Incremental Load Script:

I want that IF a QVD file found then Execute below Script else execute the last one:

//GET FROM & TO DATE FROM QLIKVIEW CONFIGURATION TABLE
QLIKVIEW_QVD_CONFIG:

SQL
SELECT
CONVERT(VARCHAR(10),[EXTRACT_FROM_DT],112) AS FROM_DT_KEY,
CONVERT(VARCHAR(10),[EXTRACT_TO_DT],112) AS TO_DT_KEY
FROM [QLIKVIEW].[QLIKVIEW_QVD_Config]
WHERE [TABLE_NAME]='STAR.FACT'
;
//GET FROM & TO DATE FROM QLIKVIEW CONFIGURATION TABLE



//ASSIGNE THE VALUES TO VARIABLES V_FROM_DATE_KEY & V_TO_DATE_KEY

LET V_FROM_DATE_KEY =Peek('FROM_DT_KEY',0,'QLIKVIEW_QVD_CONFIG');
LET V_TO_DATE_KEY =Peek('TO_DT_KEY',0,'QLIKVIEW_QVD_CONFIG');

DROP TABLE QLIKVIEW_QVD_CONFIG;
//ASSIGNE THE VALUES TO VARIABLES V_FROM_DATE_KEY & V_TO_DATE_KEY

IF FACT_DATA.QVD FOUND then

FACT_DATA:
LOAD
*
FROM (QVD)
WHERE (DATE_KEY<$(V_FROM_DATE_KEY));

CONCATENATE
LOAD
*
FROM (QVD)
WHERE (DATE_KEY>$(V_TO_DATE_KEY));

//DELETE DATA FROM QVD BETWEEN RANGE V_FROM_DATE_KEY & V_TO_DATE_KEY

//Incremental Load
CONCATENATE
SQL
SELECT    
A.*

FROM        
STAR.FACT A
WHERE    
(A. DATE_KEY BETWEEN
$(V_FROM_DATE_KEY) AND $(V_TO_DATE_KEY))

ELSE

FACT_DATA:

SQL
SELECT    
A.*

FROM        
STAR.FACT A
WHERE    
(A. DATE_KEY BETWEEN
$(V_FROM_DATE_KEY) AND $(V_TO_DATE_KEY))

Why I want to go for IF else statement because when 1st time I load there will not be any QVD file so Without IF ELSE my Script will throw an error.

So That's why I want to handle it with IF ELSE. If specified QVD file found then Execute 1st query else execute 2nd query.

2 Replies

Re: IF else condition while scripting Incremental Load

IF len(filetime('FACT_DATA.QVD'))>0 THEN

     ...

ELSE

     ...

END IF


talk is cheap, supply exceeds demand
bestofwest
Contributor II

Re: IF else condition while scripting Incremental Load

You can also use ErrorMode:

set ErrorMode=0;

load * from abc.qvw;

if ScriptError=8 then   // File not found in this case

     //no file;

end if

Community Browser