-
Re: Dynamic variable in String
sushil kumar Dec 20, 2017 3:40 AM (in response to Christoph Albrecht)Try this: Let v2 = 'v1 is'& $(v1);
-
Re: Dynamic variable in String
Christoph Albrecht Dec 20, 2017 4:04 AM (in response to sushil kumar)That is also not working. Its the same result. The string is only evaluated once :/
-
Re: Dynamic variable in String
Marcus Sommer Dec 20, 2017 4:27 AM (in response to Christoph Albrecht)How do you call the variable - with $(v2) or with '$(v2)' and where?
- Marcus
-
Re: Dynamic variable in String
Christoph Albrecht Dec 20, 2017 4:37 AM (in response to Marcus Sommer )I tried both $(v2) and '$(v2)'. I'm using the variables in the data load script.
-
Re: Dynamic variable in String
Marcus Sommer Dec 20, 2017 4:47 AM (in response to Christoph Albrecht)How do you check the content of the variables? Did you try:
trace $(v1);
trace $(v2);
trace '$(v2)';
- Marcus
-
Re: Dynamic variable in String
Christoph Albrecht Dec 20, 2017 4:51 AM (in response to Marcus Sommer )Trace($(v1));
Trace($(v2));
Trace('$(v2)');
-->
(2)
(v1 is 1)
('v1 is 1')
-
Re: Dynamic variable in String
Marcus Sommer Dec 20, 2017 5:06 AM (in response to Christoph Albrecht)If I look again on this I think it couldn't work in this way. The important point is when is v2 evaluated and this is before v1 is changed to 2 and therefore didn't impact this change the content of v2 anymore.
What is the aim of your task? Maybe there are other ways to get to your target.
- Marcus
-
Re: Dynamic variable in String
Christoph Albrecht Dec 20, 2017 5:12 AM (in response to Marcus Sommer )I wanted to use a SELECT statement in a variable multiple times. And inside the SELECT statement is a variable which is changing. The easiest way is to copy the statement multiple times. But I wanted to avoid this.
-
Re: Dynamic variable in String
Marcus Sommer Dec 20, 2017 5:22 AM (in response to Christoph Albrecht)I think you could use parametrized variables for it - maybe something like this:
let v1 = 'select * from SOURCE where Date >= $1;';
let v2 = '$(v1(''20.12.2017''))';
trace $(v1);
trace $(v2);
- Marcus
-
Re: Dynamic variable in String
Christoph Albrecht Dec 20, 2017 6:12 AM (in response to Marcus Sommer )Oh, yes that is possible.
I tried it. I have two variables. So I can do:
Let v1 = 'this is param1 $1 and this is param2 $2';
Let v2 = '$(v1("1 2 3", "1, 2, 3"))';
Trace $(v2);
But the second varible has a comma inside the string. And the result is then:
--> this is param1 "1 2 3" and this is param2 "1;
How can I avoid that?
-
Re: Dynamic variable in String
Andrea Gigliotti Dec 20, 2017 6:54 AM (in response to Christoph Albrecht)you could use a semicolon rather than comma as below:
Let v1 = 'this is param1 $1 and this is param2 $2';
Let v2 = '$(v1("1 2 3", "1;2;3"))';
and after replace semicolon with comma.
Let v3 = Replace(v2, '|', ',');
Trace $(v3);
-
Re: Dynamic variable in String
Marcus Sommer Dec 20, 2017 7:18 AM (in response to Christoph Albrecht)Unfortunately there is no way to mask a comma within a variable-parameter so that you need workarounds with replace or similar like hinted by Andrea or to avoid them completely. Are there not many possible parameter sub-parts (delimited by the comma) you could just use more parameters. But I assume you want to use field-lists or even expressions and than it would be quite ugly with a variety of parameters.
Please provide some more context to your task because I believe there could be other ways, too. I mean examples of v1 and v2 and how they are created and called - in any loops?
- Marcus
-
-
-
-
-
-
-
-
-
-
-
Re: Dynamic variable in String
Andrea Gigliotti Dec 20, 2017 4:48 AM (in response to Christoph Albrecht)try the below statement:
Let v2 = '=v1 is ' & $(v1);
on the UI use v2 without dollar expansion $.
-
Re: Dynamic variable in String
Christoph Albrecht Dec 20, 2017 4:48 AM (in response to Andrea Gigliotti )-
Re: Dynamic variable in String
Andrea Gigliotti Dec 20, 2017 4:56 AM (in response to Christoph Albrecht)what do you get on the UI creating a Text object with expression =v2 ?
-
Re: Dynamic variable in String
Tatsiana Chetirbok Dec 20, 2017 5:13 AM (in response to Andrea Gigliotti )he doesn't use text object. he needs the variables only in script
-
-
Re: Dynamic variable in String
Andrea Gigliotti Dec 20, 2017 5:09 AM (in response to Christoph Albrecht)i'm using Qlik Sense November 2017 SR1 and below the script used:
Let v1 = 3;
Let v2 = '=v1 is ' & $(v1);
trace $(v1);
trace $(v2);
each time you change value of variable v1 also the variable v2 is changed accordingly.
-
Re: Dynamic variable in String
Christoph Albrecht Dec 20, 2017 5:15 AM (in response to Andrea Gigliotti )Yes thats right.
But it is not working again if you change v1 again:
Let v1 = 3;
Let v2 = '=v1 is ' & $(v1);
trace $(v1);
trace $(v2);
Let v1 = 4;
trace $(v1);
trace $(v2);
-->
3
=v1 is 34=v1 is 3-
Re: Dynamic variable in String
Andrea Gigliotti Dec 20, 2017 5:19 AM (in response to Christoph Albrecht)Yes but it works as expected in script.
It's like a programming language you have to assign the new value of v1 to v2 as below:
Let v1 = 3;
Let v2 = '=v1 is ' & $(v1);
trace $(v1);
trace $(v2);
Let v1 = 4;
Let v2 = '=v1 is ' & $(v1);
trace $(v1);
trace $(v2);
-
-
-
-