Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Condition (if - then) inside a load procedure

Can I insert a condition (if - then) inside a load procedure?

ex:

CLIENTI:

load

     cod_cliente as id_cliente,

     cod_agente as id_agente,

     if(vDocumentName='Example') then

          cod_raccolta as id_raccolta,

     end if

     flag_intest as intest

from Cliente.qvd

I hope I was clear enough.

thx!!!

6 Replies
avinashelite

Yes you can

if A>0 then

Code

End if 

avinashelite

If..then..elseif..else..end if

The if..then control statement is a script selection construct forcing the script execution to follow different paths depending on one or several logical conditions. The syntax is:

if condition then

  [ statements ]

{ elseif condition then

  [ statements ] }

[ else

  [ statements ] ]

end if

Where:

condition is a logical expression which can be evaluated as true or false.

statements is any group of one or more QlikView script statements.

Since the if..then statement is a control statement and as such is ended with either a semicolon or end-of-line, each of its four possible clauses (if..then, elseif..then, else and end if) must not cross a line boundary.

Examples:

if a=1 then

load * from abc.csv;

sql select e, f, g from tab1;

end if

if a=1 then; drop table xyz; end if;

if x>0 then

load * from pos.csv;

elseif x<0 then

load * from neg.csv;

else

load * from zero.txt;

end if

MK_QSL
MVP
MVP

What exactly you want to do in load script?

Can you describe little more please?

Not applicable
Author

But have you seen the example that I have attached together with my application?

I have to choose whether or not to load a FIELD according to the document name.

FIELD, NOT QVD

sunny_talwar

What is vDocumentName here? a variable? How do you determine its value?

marcus_sommer

You could implement an if-loop as a control-statement outside from a load-statement (take a look on the suggestion from avinashelite) or within the load as a function. In your case you could with:

CLIENTI:

load

    cod_cliente as id_cliente,

    cod_agente as id_agente,

    if(DocumentName()='Example'), cod_raccolta, null()) as id_raccolta,

    flag_intest as intest

from Cliente.qvd (qvd);

load these fieldvalues or NULL or any default-value within a new field but you couldn't avoid the creation of this new field. I think better than this would be the following:

CLIENTI:

load

    cod_cliente as id_cliente,

    cod_agente as id_agente,

    cod_raccolta as id_raccolta,

    flag_intest as intest

from Cliente.qvd (qvd);

if DocumentName() <> 'Example' then

     drop fields id_raccolta;

end if


because your table will have this field only if the condition is met and your load will be remain optimized because no transforming is made unless the renaming which won't break it.


- Marcus