2 Replies Latest reply: Mar 14, 2015 9:24 PM by Antonio Caria RSS

    IF else condition while scripting Incremental Load

    Shivendoo Kumar

      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 [D:\FACT_DATA.QVD](QVD)
      WHERE (DATE_KEY<$(V_FROM_DATE_KEY));

      CONCATENATE
      LOAD
      *
      FROM [D:\FACT_DATA.QVD](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.