Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Use variables in Load expression

LEGEND:

"tempXlsPlanChart" is a Qlikview table imported table from Excel.

"tempXlsPlanChartColumn" is a Qlikview table imported from SQL server ,consists of "tempXlsPlanChart" columns with some attributes.  "ClmnXls" is the desired one.

I'm trying to create new Qlikview table within the script editor that loads from "tempXlsPlanChart " only the columns that are specified in "tempXlsPlanChartColumn" table.

SCRIPT :

//Concat delivers the column names (as one string with comma delimiter) from tempXlsPlanChart to vStr variable

SET vStr=Concat(ClmnXls, ', ');

Table:

//the vStr variable expends to its string value and creates the column names in the Load statement.

LOAD $(vStr)

RESIDENT tempXlsPlanChart;

DROP TABLE tempXlsPlanChart;

PROBLEM :

When the compiler runs it doesn't expand the variable in the LOAD statement, and sends error message.


Does some one have a clue how to solve this problem ?

18 Replies
alexandros17
Partner - Champion III
Partner - Champion III

Try with

LOAD $(=vStr)


or


LOAD $(=$(vStr))



let me know

Not applicable
Author

Fast replied!

But unfortunately the compiler send Syntax Error message,

This time the variable expansion is null.

ThornOfCrowns
Specialist II
Specialist II

Make sure vStr doesn't have an extra comma on the end of the last fieldname.

Not applicable
Author

have you tried LET instead of SET ?

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

SCRIPT :

//Concat delivers the column names (as one string with comma delimiter) from tempXlsPlanChart to vStr variable

SET vStr=Concat(ClmnXls, ', ');

The only thing this does is create a variable vStr with the value 'Concat(ClmnXls', ','). It does not create a variable with a comma separated list of column names. If you want that you need something like this:

Tmp:

load concat(ClmnXls, ',' ) as ColumnNames

Resident tempXlsPlanChartColumn;

LET vStr = peek('ColumnNames');

Drop Table Tmp;

Table:

Load $(vStr)

Resident tempXlsPlanChart;


talk is cheap, supply exceeds demand
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

I think you need something like this:

....

ConcatFields:

LOAD Concat(ClmnXls, ',') As ConcatFields

RESIDENT tempXlsPlanChartColumn;

Let vStr = Peek('ConcatFields');

DROP Table ConcatFields;

Table:

LOAD $(vStr)

RESIDENT tempXlsPlanChart;

....

I am not sure if I understand your field names and table clearly, so you may need to adjust this to get it to work.

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

The Concat function don't create extra comma.

Not applicable
Author

The compiler sends error message also when using LET function (variable expansion is null).

Not applicable
Author

The compiler doesn't execute the concat function it leaves it as : concat(distinct ClmnXls, ',' ). and therefore error message occurs.