tDBInput, where condition context variable date issue

Highlighted
Six Stars

tDBInput, where condition context variable date issue

Hi everyone

I tried to add a context variable "Start" which is a date type.
If I start my talend job I'm able to choose a date but after that there are always errors.

 

06-08-_2019_11-49-07.png


Can't figure out how solve this issue


This is my example query:

 

select invno 
from invoicedata

where convert(date, invoicedata.invno,104)=convert(date,(TalendDate.formatDate("yyyy-MM-dd HH:mm:ss",context.Start) ),104)

 

Thanks for any advice. 


Accepted Solutions
Community Manager

Re: tDBInput, where condition context variable date issue

Is the code you have shown what is in your DB component? You need to keep in mind that the SQL you put in your component is actually a Java String. So you need to build it like a Java String. For example, if you want to add a context variable to a WHERE Clause, you need to do something like below....

 

"SELECT
MyColumn1,
MyColumn2,
MyColumn3,
MyColumn4
FROM MyTable
WHERE MyColumn1 = '"+context.MyParam+"'"

The assumption above being that the data type of MyColumn1 and context.MyParam is String.


All Replies
Community Manager

Re: tDBInput, where condition context variable date issue

Is the code you have shown what is in your DB component? You need to keep in mind that the SQL you put in your component is actually a Java String. So you need to build it like a Java String. For example, if you want to add a context variable to a WHERE Clause, you need to do something like below....

 

"SELECT
MyColumn1,
MyColumn2,
MyColumn3,
MyColumn4
FROM MyTable
WHERE MyColumn1 = '"+context.MyParam+"'"

The assumption above being that the data type of MyColumn1 and context.MyParam is String.

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog