Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Variables' definition

Hi all,

Do anyone know how to use the result of a SQL sentence as the variable's value?

Thanks and best regards,

CoCo

17 Replies
Not applicable
Author

You may compute the data directly during the script also and store the result into table.

You may also create lots of variables (MyVar1, MyVar2, MyVar ...) such a way:

 

let counter=1;

do while counter < NoOfRows('Meas')
MyVar$(counter)=peek('Measures', counter-1, 'Meas');
counter=counter+1;
loop

Fabrice

Not applicable
Author

Hi Sokkorn,

Please see the above reply.

Sokkorn
Master
Master

Hi CoCo,

Here is sample one

//This statement is to fetch Max date from field DateField.

[MaxDateTable]:

  LOAD Max(DateField) AS [MaxDateValue];

SQL Select DateField From TableName;

//Here is variable vMaxDate where it get value from table above with format YYYY-MM-DD. Ex. 2014-01-21

Let vMaxDate = Date(Peek('MaxDateValue',0,'MaxDateTable'),'YYYY-MM-DD');

Regards,

Sokkorn

jonathandienst
Partner - Champion III
Partner - Champion III

CoCo Xi wrote:

But when I use the same sentence in the "Variable Overiew" window, it occurs the grammar errors.

I don't know why!

Hi

I wouldn't worry about those. QV is trying to interpret the text as a QV expression, and the SQL is not a valid QV expression and QV will pass this to the database server for evaluation.

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Sokkorn
Master
Master

Hi CoCo,

For this one, I would suggest you load all data from Account table. Like this

[Age]:

SQL Select [Account ID],[Account Name], [Age] From Account;

Create new variable in "Variable Overview" by click Add:

     1. Variable name: vAge2635

     2. Definition: Count({$<[Age]={'26-35'}>} [Account ID])

Regards,

Sokkorn

Not applicable
Author

Oh, how to definite the variable using the result of a SQL sentence correctly?

Not applicable
Author

Oh, great , thanks very much!

But is this the simplest method ? As I'll create many variables like vAge2635.

Not applicable
Author

Oh, dear!

It works. Thank you!!!

CoCo