Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
helen_pip
Creator III
Creator III

How to add variables to a table in a script

Dear Qlikview user

I have declared the following variables in a load script, but I would like them to be stored into a table in the script

I.e.

Variables:

$(vField_OPD1_Table) = 'Division';

$(vField_OPD2_Table) = 'Care_Group';

From...........

Can anyone kindly help

Kind Regards

Helen

9 Replies
jpenuliar
Partner - Specialist III
Partner - Specialist III

You can use variables in your load script like below:

Table:

Load

...

...

$(vField_OPD2_Table) as FieldName

...

...

;

jpenuliar
Partner - Specialist III
Partner - Specialist III

you can also define your variable to accept an input and return an output like below:

Let IsEmpty = If(Isnull($1),'Yes','No');

then use during load as:

$(IsEmpty([Field_to_Qualify])) as Flag_Empty,

helen_pip
Creator III
Creator III
Author

Hello Jonathan

So far I have done this

1. Declared the variables

LET vField_OPD1_Table = 'Division';

LET vField_OPD2_Table = 'Care_Group';

2. Added in a table

DivVar:

Load

$(vField_OPD2_Table) as 'Divvar',

'DIV' AS 'DivisionName';

However the script is now erroring, do  have to have a from or resident clause for my DivVar table?

Kind Regards

Helen

jpenuliar
Partner - Specialist III
Partner - Specialist III

Hi Pippard,

so its practically same as

...

'Division' as 'Diwar',

...

Anil_Babu_Samineni

This is not the calculated variables try to shift SET from LET

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
jpenuliar
Partner - Specialist III
Partner - Specialist III

Is 'Division' a field in your Resident Table?

helen_pip
Creator III
Creator III
Author

Hello Jonathan

Yes, Division is in my main fact table and I can resident load it in

However all I want achieve is a table which contains the word "Division" through a variable (Which the variables is doing") and an additional dummy field in the table

I.e. Table results to be in 2 columns

Division                  Div

Division                  Div

Care_Group            CG

Care_Group            CG

The first column will come from the variable and the seocnd column is the dummy field.

However my table is failing to load

Kind Regards

Helen

Ultimately I am try to achieve this: Set the active field in a cyclic group.qvw

tracysmart
Creator II
Creator II

Hi Helen

try something like this


SET vField_OPD1_Table = 'Division';





DivVar:
Load
'$(vField_OPD1_Table)' as Divvar
AutoGenerate(1);

Steveo250k
Contributor II
Contributor II

Bingo, this did it for me.  My code was exactly like the above.  Didn't work.  But when I switched LET to SET, it worked.  IMHO, this is a POS coding syntax.  Qlik makes easy things very hard.  

The documentation says SET does assignment without calculation.  That is, SET assigns a literal.  But I have a function call on the right side of the equals sign.  In my book that amounts to a calculation.  E.g., A + B is a calculation SUM(A, B) would likewise be a calculation.

But, apparently, Qlik doesn't see it that way.

SET v_QVD_last_update = QVDCREATETIME('lib://QVD_Extract\f_qlik_load.qvd');     puts the time into the variable.

LET  v_QVD_last_update = QVDCREATETIME('lib://QVD_Extract\f_qlik_load.qvd');   causes an error when I try to look at the time. 

The error occurred here:
data_load: LOAD *,
         2019-08-01 >>>>>>12<<<<<<:03:13 AS QVD_last_update