Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
vladimirkup
Contributor III
Contributor III

where clause

Hello all,

i am new to QLIK Sense developing and looking for help.

how do i code  in Qlik Sence the following simple SQL query :

SELECT * FROM Table1
WHERE date = (SELECT MAX(date) FROM Table1)

i tried to do it with variable, something like this

set param1 =  (SELECT MAX(date) FROM Table1)

Table2:

load *

resident Table1

where date = $'param1'

but that don't work.

 

please help

Thanks in advance

2 Solutions

Accepted Solutions
marcus_sommer

Try it with:

... where date = $(param1) ...

- Marcus

View solution in original post

marcus_sommer

My suggestion was aimed to assign a string to a variable. But now I have the impression that you want to execute a query and assign the query-result to the variable - that's not possible. To get this you need to something like the following:

t: sql select max(date) as t from table;

set param1 = peek('t', 0, 't');

Depending on the target-query you may also need some formatting with date() and setting the variable-call within quotes like: '$(param1)'.

- Marcus

View solution in original post

4 Replies
marcus_sommer

Try it with:

... where date = $(param1) ...

- Marcus

vladimirkup
Contributor III
Contributor III
Author

HI,

that didn't work. i think this line does not work:

set param1 =  (SELECT MAX(date) resident Table1)

 

when i execute in debug mode i do not see the param1 result in the output section.

is it even possible to set a variable from a query ? or is it just a syntax issue ?

marcus_sommer

My suggestion was aimed to assign a string to a variable. But now I have the impression that you want to execute a query and assign the query-result to the variable - that's not possible. To get this you need to something like the following:

t: sql select max(date) as t from table;

set param1 = peek('t', 0, 't');

Depending on the target-query you may also need some formatting with date() and setting the variable-call within quotes like: '$(param1)'.

- Marcus

vladimirkup
Contributor III
Contributor III
Author

Thanks for the solution !