Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
chichibio
Contributor III
Contributor III

Result Query to context variable

Hi,
I'would store the result of query in variable and use this variable in new query.
For example:
query: select max(a) from table
tMysqlInput-> in context variable.
I define context variable in this way:

0683p000009MFjM.png


wrong I ?
Thnx at all

Labels (2)
4 Replies
JR1
Creator III
Creator III

No need to use a context for this. You can achieve this by using e.g. tOracleInput/tMySqlInput/... --> tFlowToIterate --> tOracleInput/tMySqlInput/... --> (everything else you want to do). The first input represents your query posted above (select max(a) from table). 
In tFlowToIterate you convert the input into a global variable which you can use in your next input like this: 
"select XYZ from TABLE2 WHERE COLUMN = " + ((String)globalMap.get("a")) 
(assuming that you named the column "a" in the schema of the first input and that it is of a numeric type).
chichibio
Contributor III
Contributor III
Author

JoRoesecke wrote:
No need to use a context for this. You can achieve this by using e.g. tOracleInput/tMySqlInput/... --> tFlowToIterate --> tOracleInput/tMySqlInput/... --> (everything else you want to do). The first input represents your query posted above (select max(a) from table). 
In tFlowToIterate you convert the input into a global variable which you can use in your next input like this: 
"select XYZ from TABLE2 WHERE COLUMN = " + ((String)globalMap.get("a")) 
(assuming that you named the column "a" in the schema of the first input and that it is of a numeric type).

Hi Jo...thank you so much to your suggest. It's very simple. 
My job going execute fine, but no rows insert in my 2nd table:
I would compare the column_date to select new elements from 2nd table and insert/update in first table.
I would : select max(date) as a from table1->result in variable-> "select * from table2 where column_date >"+((String)globalMap.get("a"))
I think that is not string. Exist ((Date)globalmap.get("a")) ? 
How I can do it?

Thank so much
0683p000009MFjR.png
Anonymous
Not applicable

Click on the "row1" link. Take a look at the schema. The tFlowToIterate will save the column data to the globalMap using the following format....

[rowname].[columnname]

So if your row1 link has a column called "myColumn", the tFlowToIterate will save it to a key of "row.myColumn". It is case sensitive. 

So your query would be...

"select * from table2 where column_date >"+((String)globalMap.get("row1.myColumn"))
chichibio
Contributor III
Contributor III
Author

rhall_2.0 wrote:
Click on the "row1" link. Take a look at the schema. The tFlowToIterate will save the column data to the globalMap using the following format....

[rowname].[columnname]

So if your row1 link has a column called "myColumn", the tFlowToIterate will save it to a key of "row.myColumn". It is case sensitive. 

So your query would be...

"select * from table2 where column_date >"+((String)globalMap.get("row1.myColumn"))

thnx to your suggest. But exactly I had problem with string, so I change that in this way:
"select * from tabl2 where column_date > '"+((java.util.Date)globalMap.get("row1.column_date"))+"'";

Finally I had click on row1 but I selected only column_date without other column from table1.
I resolved with your suggest and other little change

thnx at all