Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

thnkgreen
Contributor

Where to put Switch Case statement: Load or SQL SELECT?

Hello to all.  I am trying to write a load statement with a switch case in it.  For some reason, this is not working.  I was wondering if you can put a switch case in a load statement, and if so, why mine is not working.

SYSyPSPULL:

LOAD PSPLN As TASK,

     PSCASN,

     PSSEA,

     PSLTYP,

     PSAREA,

     PSZONE,

     PSAISL,

     PSBAY,

     PSLEVL,

     PSPOSN,

     PSSYR,

     PSSTYL,

     PSSSFX,

     LEFT(PSSYR & PSSTYL & PSSSFX,3) AS SAPMERCHDIVISIONCODE,

     PSSYR & PSSTYL & PSSSFX AS SKU,

     PSSZDS,

     PSSQTY,

     PSQPUL,

     PSRLOC,

     PSSTAT,

     PSDCR,

     PSCRT;

    

     SWITCH RESERVELOCATION

     CASE 001

         LOAD TRIM(PSAREA) & TRIM(PSZONE) & Left(TRIM(PSAISL),1) & Right(TRIM(PSAISL),1) & TRIM(PSBAY);

     CASE 003

         LOAD TRIM(PSAISL) & TRIM(PSLEVL) & TRIM(PSPOSN);

     DEFAULT

        LOAD TRIM(PSAISL) & TRIM(PSLEVL) & TRIM(PSPOSN);

     END SWITCH;

SELECT * FROM PKMANH221D.PSPULL00

WHERE PSCRT ='1' AND PSDCR >= $(zconvDate);

3 Replies
thnkgreen
Contributor

Re: Where to put Switch Case statement: Load or SQL SELECT?

Thank you for the quick response. Unfortunately this does not answer my question. I am trying to understand if the switch statement will work in a Load statement or if it has to be used only in the SQL Select kind of statement. Thanks.

MVP
MVP

Re: Where to put Switch Case statement: Load or SQL SELECT?

Hi,

Try like this

SYSyPSPULL:
LOAD PSPLN As TASK,
     PSCASN,
     PSSEA,
     PSLTYP,
     PSAREA,
     PSZONE,
     PSAISL,
     PSBAY,
     PSLEVL,
     PSPOSN,
     PSSYR,
     PSSTYL,
     PSSSFX,
     LEFT(PSSYR & PSSTYL & PSSSFX,3) AS SAPMERCHDIVISIONCODE,
     PSSYR & PSSTYL & PSSSFX AS SKU,
     PSSZDS,
     PSSQTY,
     PSQPUL,
     PSRLOC,
     PSSTAT,
     PSDCR,
     PSCRT,
    
     If( RESERVELOCATION = '001', TRIM(PSAREA) & TRIM(PSZONE) & Left(TRIM(PSAISL),1) & Right(TRIM(PSAISL),1) & TRIM(PSBAY)
     If(RESERVELOCATION = '003', TRIM(PSAISL) & TRIM(PSLEVL) & TRIM(PSPOSN),
     TRIM(PSAISL) & TRIM(PSLEVL) & TRIM(PSPOSN))) AS DimensionName;   
SELECT * FROM PKMANH221D.PSPULL00
WHERE PSCRT ='1' AND PSDCR >= $(zconvDate);

Hope this helps you.

Regads,

Jagan.

MVP
MVP

Re: Where to put Switch Case statement: Load or SQL SELECT?

SWITCH  CASE works in LOAD script. What is the error you are getting? You can try something like:

CASE '001'   ........... if they are not numeric.

Community Browser