take a value from a sql table and save it in a variable

Six Stars

take a value from a sql table and save it in a variable

Hi, I should extract a value from a table and save it in a variable and then use it in a subsequent query. I'm a beginner. Can someone good-hearted help me? :-)


Accepted Solutions
Employee

Re: take a value from a sql table and save it in a variable

Hi,

 

     I understand that you are trying to get the value for the post mentioned below.

 

https://community.talend.com/t5/Design-and-Development/Where-clause-dynamic-postgresql-with-date/m-p...

 

Lets try to do it in slightly different way.

 

Step 1:- Create a context variable max_date with String data type

 

Step 2:- Assign the value from database to context variable as shown below. Make sure that your data from database is fetched in the format YYYYMMDD and converted to String. If you want the value in different format, make sure that the format is in sync everywhere.

image.png

 

 

Now, you have the value in the context variable which can be used in the whole job. Please note that you can use the Global variables also. In that case, you need to assign the Global variable in String format as argument to your next post.

 

Hope it helped to resolve your issue :-)

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)

 

 

 

 


Warm Regards,
Nikhil Thampi
Please appreciate our members by giving Kudos for spending their time for your query. If your query is answered, please mark the topic as resolved :-)

All Replies
Seven Stars

Re: take a value from a sql table and save it in a variable

Hi,
You can use globalvariable to get and put in a query as mentioned below
1.Use tsetGlobal varaible component
2.In tsetGlobal variable assign value and name to that global variable
3.Use global.get("name assigned in the tsetglobalvariable")
4.To get as a string use (String)global.get("name assigned in the tsetglobalvariable")
Let me know on any queries

Regards,
Kasthuri Rengan
Six Stars

Re: take a value from a sql table and save it in a variable

Thanks for the reply. As I said, I'm a beginner. I have a scheme as below but talend says:

"MaxDate cannot be resolved to a variable"

 

Cattura.JPGCattura.JPG

Nine Stars

Re: take a value from a sql table and save it in a variable

put it in double quotes "MaxDate"

Regards
Abhishek KUMAR
( Please mark the post as resolved if you found your solution )
Six Stars

Re: take a value from a sql table and save it in a variable

Ok but...

I have this situation:

1: I run the first query:

"SELECT
 max(  PUB.uoggetto.dtvartime) as MaxDtvartime
FROM PUB.uoggetto"

2: I would like to save a MaxDate variable

3 run a new queri using the variable

"SELECT
 *
FROM PUB.uoggetto

where dtvartime = 'variable' Cattura.JPG"

 

Seven Stars

Re: take a value from a sql table and save it in a variable

Hi ,

 

Can you show me the screeshot of tsetglobalvariable component?

 

Regards,

Kasthuri Rengan

Six Stars

Re: take a value from a sql table and save it in a variable

Cattura.JPG

Seven Stars

Re: take a value from a sql table and save it in a variable

Hi ,

 

Use (Date)globalMap.get("MaxDate")) expression in the query .

 

Kindly accept this as solution 

 

Regards,

Kasthuri Rengan

Six Stars

Re: take a value from a sql table and save it in a variable

the problem is in the error above. "MaxDtvartime can not be resolved or is not a field" at setgloablvar

Nine Stars

Re: take a value from a sql table and save it in a variable

define schema in tMysqlrow where schema column name same as query result column name.

 

during select use GlobalMap get methode.

Regards
Abhishek KUMAR
( Please mark the post as resolved if you found your solution )
Nine Stars

Re: take a value from a sql table and save it in a variable

Define schema in tMysql row where schema column name same as  query result column name.

 

 

during select use GlobalMap get

Regards
Abhishek KUMAR
( Please mark the post as resolved if you found your solution )
Highlighted
Six Stars

Re: take a value from a sql table and save it in a variable

I do not use mysql but a jdbc generic because the source is openedge

Employee

Re: take a value from a sql table and save it in a variable

Hi,

 

     I understand that you are trying to get the value for the post mentioned below.

 

https://community.talend.com/t5/Design-and-Development/Where-clause-dynamic-postgresql-with-date/m-p...

 

Lets try to do it in slightly different way.

 

Step 1:- Create a context variable max_date with String data type

 

Step 2:- Assign the value from database to context variable as shown below. Make sure that your data from database is fetched in the format YYYYMMDD and converted to String. If you want the value in different format, make sure that the format is in sync everywhere.

image.png

 

 

Now, you have the value in the context variable which can be used in the whole job. Please note that you can use the Global variables also. In that case, you need to assign the Global variable in String format as argument to your next post.

 

Hope it helped to resolve your issue :-)

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)

 

 

 

 


Warm Regards,
Nikhil Thampi
Please appreciate our members by giving Kudos for spending their time for your query. If your query is answered, please mark the topic as resolved :-)

Cloud Free Trial

Try Talend Cloud free for 30 days.

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.