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

why let and why set

Hi

i know set will store the value and let will elevate the value, now i want to know why let and why set please share me the example.

i am aware of below example

set x=2+3 out put as 2+3 and i use $ then it will get 5

let  x=2+3 out put as 5

my question is where to keep left and where to keep set in real time.

Thanks and Regards,

Vinod

5 Replies
prma7799
Master III
Master III

Please check this

let and set difference

its_anandrjs

In Set values are string and in Let value get evaluated in set variable you can use this string.

See ex:-

SET vTableName = 'Table1';

LET vToday = Today();

$(vTableName):

LOAD * Inline

[

ddd

aa

];

tresesco
MVP
MVP

Here is one example of usage differences of them: Problem with date and/or variable and/or WHERE condition

avinashelite

Let

The let statement has been created as a complement to the Set statement, used for defining Script Variables. The let statement, in opposition to the set statement, evaluates the expression on the right side of the '=' before it is assigned to the variable.

The word let may be omitted, but the statement then becomes a control statement. Such a statement without the keyword let must be contained within a single script row and may be terminated either with a semicolon or end-of-line.

The syntax is:

let variablename=expression

Note that the word let may be omitted.

Set x=3+4;

Let y=3+4;

z=$(y)+1;

$(x) will be evaluated as '3+4 '

$(y) will be evaluated as '7'

$(z) will be evaluated as '8'

Example:

Let T=now( );

$(T) will be given the value of the current time.

Set

The set statement is used for defining Script Variables. These can be used for substituting strings, paths, drives, etc.

The syntax is:

set variablename=string

Examples:

Set FileToUse=Data1.csv;

Set Constant="My string";

Set BudgetYear=1997;

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Use set when you want to store a complex expression as-is in a variable.

It is a common best practice in QlikView Development to NOT duplicate identical complex expressions in different places, but to store the expression in a variable and use that variable in different places. Why? Because in the first situation (duplication) when your expression needs to be adjusted, you run the risk of forgetting to change somle instances. While in the second situation, changing the variable assignment will change ALL occurrences.

Now, to store an expression unchanged in a variable, you can use SET to avoid immediate evaluation.

Note that the righthandside of both LET and SET will be submitted to $-sign substitution, even if SET in theory shouldn't do anything with the string after the equal sign. That's because $-sign substitution is performed before the statement is parsed.