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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
jagannalla
Partner - Specialist III
Partner - Specialist III

How can i keep the conditon for sql statement in the script based on other value?

Hi,

- I had taken a table from database and created a qvd file for particular table. The qvd and table has same number of rows. Now i want to update qvd file if i inserted some records in the database. For that i written a script as follows:

//Test:
//LOAD Id,
// Sname,
// Sal;
//SQL SELECT *
//FROM QvdUpdate.dbo.Test;
//STORE Test into Test.qvd;

TestFile:
SQL SELECT Id,
Sal,
Sname
FROM QvdUpdate.dbo.Test where id > 7;
Concatenate
LOAD Id,
Sname,
Sal
FROM
Test.qvd
(qvd);
STORE TestFile into Test.qvd;

- The qvd is Updating with this code. But in the sql statement i have given the conditon manually with the value i.e 7.


- In the place of 7 i want to put max(id)(i.e the last record value of the qvd file) value which is coming from qvd file.

1 Reply
pat_agen
Specialist
Specialist

hi,

give the following code a try. This is how I do it.

// first read from qvd and find max id

loadData:
LOAD Id,
Sname,
Sal
FROM
Test.qvd
(qvd);

maxId:
select max(Id) as maxId
resident loadData;

let vmaxId=peek('maxId',-1,maxId);

drop table maxId;

// now do a concatenate laod frolm your databse for everything above the maxId
loadData:
Concatenate (loadData)
LOAD Id,
Sname,
Sal;

loadData:
SQL SELECT Id,
Sal,
Sname
FROM QvdUpdate.dbo.Test where id > $(vmaxId);


STORE loadData into Test.qvd;