Skip to main content
Announcements
See why Qlik is a Leader in the 2024 Gartner® Magic Quadrant™ for Analytics & BI Platforms. Download Now
cancel
Showing results for 
Search instead for 
Did you mean: 
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
tresesco
MVP
MVP

Try writing the entire load script under the condition like:

If conputername()='comp123' then

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

ElseIf conputername()='comp234' then

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

.....

marcus_sommer

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
Partner - Creator III
Partner - Creator III

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.