Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Parse date from globalMap

Hi!
I am using a sql query with parameters. I am getting those parameters with the component tMsgBox as a globalvar. 
This is a part from the query with mssqlinput:
par.data > TalendDate.formatDate("dd-MM-yyyy", (String)globalMap.get("tMsgBox_2_RESULT"))  and par.data < '30-11-2015' and cli.razon like '"+(String)globalMap.get("tMsgBox_1_RESULT")+"%'

On the blue code, I can compare the parameter from the tmsgbox without problem because it's a string, but when I want to input a date with the format "dd-mm-yyyy" talend is giving me an error all the time. I just want to convert that string to a date, in order to compare this on the sql.
Labels (2)
3 Replies
TRF
Champion II
Champion II

Hi,
Think of SQL query as a String. So, you don't have to convert tMsgBox_2_Result to a Date, just compose the String as if you've type it by yourself:
"par.data > '" + (String)globalMap.get("tMsgBox_2_RESULT") + 
"' and par.data < '30-11-2015' and cli.razon like '" +
(String)globalMap.get("tMsgBox_2_RESULT") + "%'"

Hope this helps,
TRF
Anonymous
Not applicable
Author

Helps a lot. Thank you.
KarthikGs
Creator
Creator

it is not working for me, below is the error snippet

 

tDBInput_5 class java.sql.Timestamp cannot be cast to class java.lang.String (java.sql.Timestamp is in module java.sql of loader 'platform'; java.lang.String is in module java.base of loader 'bootstrap')

java.lang.ClassCastException: class java.sql.Timestamp cannot be cast to class java.lang.String (java.sql.Timestamp is in module java.sql of loader 'platform'; java.lang.String is in module java.base of loader 'bootstrap')