Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I am trying to restrict the number of rows by using context variable but it's sending all the rows from the table. All record are coming as output in query window too.
Kindly help in this regard.
Your query is wrong. You are building a SQL query using Java String manipulation. Your query should be more like this....
"SELECT * FROM actor where actor_id> '"+context.MAXID+"'"
I'd argue that you probably do not need the single quotes either, but that shouldn't cause a massive issue.
where are you storing into memory,in Talend job?
I think I know what is wrong, but you haven't shown what I need to see. Can you show me the query as text (not a screenshot) and explain the flow of data. It looks like the order of processing is wrong. Your context variable when the query is processed and fired will always be 0 as it is not set until the end of the flow. You also have a timing issue with when queries are generated and when context variables are set. A rule of thumb is that if you want to use a context variable in a query, that it needs to be set in a prior subjob (or in a previous iteration).
There is no other job associated with it . it's a single job.
Even I am able to print the MAXID coming from the variable. but issue is not restricting.
context.MAXID=input_row.MAXID;
>creating variable
"SELECT IFNULL(MAX(actor_id),0) AS MAXID FROM actor WHERE flag='Y'"
>This is to get the maximul actor_id from the table with flag='Y'
If table has 100 rows I need to show only 10 rows based on variable
"SELECT * FROM actor where actor_id> '+context.MAXID+' "
This is to restrict the rows.
Let me know if you need more info.
Thanks
Your query is wrong. You are building a SQL query using Java String manipulation. Your query should be more like this....
"SELECT * FROM actor where actor_id> '"+context.MAXID+"'"
I'd argue that you probably do not need the single quotes either, but that shouldn't cause a massive issue.
you need to load MAXID into context using tcontextload.
I had that initially (extra " ") but removed , anyway changed query, it's working as expected.
Thanks a lot..