Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

Qlik: Loading from Flat Files based on environment

Hi,

I have a requirement to load data from a flat file based on the environment the reload is happening in. Is there a way to achieve this? I was searching through the forum and found a few posts that talk about different connections based on environment / computer name:

For the connection, the suggestion from @Ralf Becher on another post was to use something like this:

if ComputerName() = 'COMPUTER_A' then

     CONNECT DB1....;

elseif ComputerName() = 'COMPUTER_B' then

     CONNECT DB2....;

else

     exit script;

end if

How could I do something similar using files? I have tried doing:

LOAD Name,

  Age,

  Sex

FROM

if ComputerName() = 'comp123' then

[\\......\test1\test.txt]

(txt, codepage is 1252, embedded labels, delimiter is ',', msq);

elseif

ComputerName() = 'comp324' then

[\\......\test4\test.txt]

(txt, codepage is 1252, embedded labels, delimiter is ',', msq);

end if

but that does not seem to work. Please let me know if there are other ways of doing this.

Thanks

3 Replies
MVP
MVP

Re: Qlik: Loading from Flat Files based on environment

Try writing the entire load script under the condition like:

If conputername()='comp123' then

     Load ...... From <Source1>;

ElseIf conputername()='comp234' then

      Load ...... From <Source2>;

.....

Re: Qlik: Loading from Flat Files based on environment

To avoid redundant code you could check and store the computer within a variable and use these variable as PathFile, example:

let PathFile = pick(match(computername(), 'comp123', 'comp234'), '\\......\test1\test.txt', '\\......\test4\test.txt');

Load * From $(PathFile) (txt, codepage is 1252, embedded labels, delimiter is ',', msq);

- Marcus

martynlloyd
Contributor III

Re: Qlik: Loading from Flat Files based on environment

I use a config file, which is a qvs file containing the local environment settings.

The first line of my script points to that file (I have common folder achitecture across environments)

$(Must_Include= mypath\QVConfig.qvs

You could set a varible in this file, and use it as above.

Regards,

Marty.

Community Browser