Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Conditional ODBC selection in script

Hi guys,

I need to load my data from 2 different datasources by made of an external flag; I wrote an external TXT file where I stored a number which indicates the firm.

My external Ditta.txt file contains only:

SET Ditta=0;

or

SET Ditta=1;

In the script I used;

$(include=Ditta.txt);

So I have the value 0 for the first firm or the value 1 for the second one in the variable Ditta and then I need to use it to redirect the ODBC, but I'm not able to do it.

Can someone help me, please?

Thanks.

N.

1 Solution

Accepted Solutions
Kushal_Chawda

IF $(Ditta) = 0 THEN

     Connection String for Ditta=0 // ODBC .....

ELSE

    Connection String for Ditta=1 // ODBC .....

ENDIF

Edit : corrected syntax

View solution in original post

6 Replies
m_woolf
Master II
Master II

IF $(Ditta) = 0 THEN

     Set vConnect = 'Your 0 connection string';

ELSE

     Set vConnect = 'Your 1 connection string';

END

ODBC CONNECT TO $(vConnect);

jonathandienst
Partner - Champion III
Partner - Champion III

Rather than using the include file to set a flag, followed by logic in the model to interpret the flag, why not simplify things by putting the connection string in the include file instead (one per include file)?

Oh, and I would use must_include instead of include, so that a missing include file causes an error in the correct place, rather some obscure later error caused by the missing include file.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Kushal_Chawda

IF $(Ditta) = 0 THEN

     Connection String for Ditta=0 // ODBC .....

ELSE

    Connection String for Ditta=1 // ODBC .....

ENDIF

Edit : corrected syntax

Anonymous
Not applicable
Author

Thank you for the reply; closing the instruction with END it returns a syntax error; I used ENDIF and it works properly 🙂

Anonymous
Not applicable
Author

Thank you for the suggestion; I have to make a little modification to my scripts to apply everywhere!!

Kushal_Chawda

Yeah, that was syntax error. Btw, I have edited my response. Thanks for marking it as correct.