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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to assign a SQL-Query-result to a variable?

Hello,

following Question:

I got a SQL-statement which provides the maximum of a database field.

For example: select max(field1) as result from table1

How can I assign this sql-result-value to a qlikview-variable?

let @vMAXIMUM = ?

Thanks for your help!

Daniel

Labels (1)
1 Solution

Accepted Solutions
Not applicable
Author

Hi,

LOAD the sql into a table

use the peek() function to populate your variable

drop the table

Fabrice

View solution in original post

5 Replies
Not applicable
Author

Hi,

LOAD the sql into a table

use the peek() function to populate your variable

drop the table

Fabrice

CELAMBARASAN
Partner - Champion
Partner - Champion

It cannot be assigned directly

try like this

Table1:

SQL SELECT Max(field1) as Result FROM table1;


LET vMAXIMUM = Peek('Result', 'Table1');


DROP Table Table1;

tresB
Champion III
Champion III

Try like:

Load Max(field1) as MaxValue;

SQL Select field1 From <data source>;

Let vMax=Peek('MaxValue');

Not applicable
Author

Thanks for your incredible fast help!

rvsaraswat
Contributor
Contributor

Hi, I am doing the same but getting a null value in the variable.

A:
SQL
select trunc(max(Event_Date)) as Result from Event;

LET vMaxDate = peek('Result','A');

Please help