Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
BA621858188
Creator
Creator

selecting table from mysql based on date condition

Hi All,

I want to retrieve the data from mysql table based on date 2022-07-24 in dynamic way.

select * from table where loaddate= '2022-07-24'(need to update with dynamic)

what need to use here to go with dynamic way and I dont want to use context need to use in query only.

Thanks

Labels (2)
7 Replies
Anonymous
Not applicable

Using context variable and update the value of context variable dynamically in the job. eg:

"select * from table where loaddate= '+context.loaddate+"'"

before the subjob starting with tMysqlInput, you can update the value of context variable dynamically on a tJava, eg:

tJava

|onsubjobok

tMysqlInput...

 

on tJava:

context.loadate=TalendDate.formatDate("yyyy-MM-dd",TalendDate.getCurrentDate());

 

//TalendDate.getCurrentDate() returns the current date, how/where does the loaddate come from in your case?

 

 

Regards

Shong

NCrawford1658815487
Contributor
Contributor

I'm having the same problem as the others.

BA621858188
Creator
Creator
Author

Hi @Shicong Hong​ 

 

if we want to do at DB component level what we can add like you have mentioned to have context parameter.

 

Any alternate way other than context param?

 

Thank you

BA621858188
Creator
Creator
Author

are you able to do filter in DB itself using dynamic way.

Anonymous
Not applicable

what do you mean 'at DB component level? provide the value by user who run the job during the job execution? or load the value from somewhere?​

BA621858188
Creator
Creator
Author

Hi @Shicong Hong​ 

 

I have tdbinput where I am using mysql conn and below query

 

select * from table where loaddate='<date>'

 

I am using hardcode value as of now but wanted to use the date in dynamic way but without using the context value.

Anonymous
Not applicable

@Vrushabh Malbari​ , Maybe I don't understand your requirement well, if you don't use context variable or global variable, how do you pass the value to the query at runtime? Can you explain what is the behavior you expect in dynamic way?