Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
h_prakash
Creator II
Creator II

Variable Help

Hi All,

I have created a connection string in Txt file and calling it through include statement. And I have assigned a variable to this include statement using Let statement. But when I am calling the variable through $ expansion to use a connection sting it throwing an red error line. Please help me in this regard.

Set vtest=$(Include =C:\Users\Test\Desktop\Inlcude/Test.txt);

$(vtest);

                        Hari:

                        SELECT * from Db;

1 Solution

Accepted Solutions
Peter_Cammaert
Partner - Champion III
Partner - Champion III

An alternative way is to use a SET statement in the Include file that sets a variable to the actual Connection string. Test.txt may contain something like:

SET vConnectionString = '[...]';

and in your Load Script, you can use that variable like this:

$(Include=C:\Users\Test\Desktop\Include\Test.txt)


OLEDB CONNECT TO $(vConnectionString);


Hari:

SELECT * FROM Db;


Always make sure that the syntax and path of the Include construct are correct. Or your variable will not be loaded and the CONNECT statement will fail.


Best,


Peter

View solution in original post

7 Replies
Peter_Cammaert
Partner - Champion III
Partner - Champion III

Why do you need a variable? You can keep it simple by just specifying the following sequence:

$(Include=C:\Users\Test\Desktop\Include\Test.txt)

Hari:

SELECT * FROM Db;

This works only on condition that your Test.txt file contains a full connect statement, like for example:

OLEDB CONNECT TO [...];

Best,

Peter

clondono
Creator III
Creator III

use "must include" in your load statement.  It will let you know if the load failed.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

An alternative way is to use a SET statement in the Include file that sets a variable to the actual Connection string. Test.txt may contain something like:

SET vConnectionString = '[...]';

and in your Load Script, you can use that variable like this:

$(Include=C:\Users\Test\Desktop\Include\Test.txt)


OLEDB CONNECT TO $(vConnectionString);


Hari:

SELECT * FROM Db;


Always make sure that the syntax and path of the Include construct are correct. Or your variable will not be loaded and the CONNECT statement will fail.


Best,


Peter

h_prakash
Creator II
Creator II
Author

Thank you the quick reply. Can we use Let instead of set in this scenario ?

Thanks

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Yes, you can. Although the SET statement is more flexible when trying to stuff a string with pesky characters (quotes, double quotes, brackets) in a variable.

Best,

Peter

h_prakash
Creator II
Creator II
Author

Thank you for the Help Peter.

Not applicable

Hi Hari,

     1) First of all variable vtest is not necessary as Peter mentioned.

     2) You cant use $(vtest).   You have to assign to another variable using let or set

                  eg: Let vtest2 = $(vtest);

-Uva