Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Context variables - can't select only the date (without its format)

Trying to select a date in the Context tab. Can?t just enter the date, must use the pop-up calendar. This brings in both the date and its format (yyyy-MM-dd;2011-02-22) which does not work when the context variable is used in a query.
Workaround: Define the context variable as a string but in the Oracle date format:
?dd-MON-yyyy?, e.g., ?22-FEB-2011?
Should I be doing something different in using the pop-up calendar?
Labels (2)
7 Replies
Anonymous
Not applicable
Author

Hi
Define the context variable as a string, and then parse it to a Date with specify format, eg:
"select * from tableName where mydate="+TalendDate.parseDate("dd-MMM-yyyy", context.mydate)
Best regards
Shong
Anonymous
Not applicable
Author

Thanks for the info -
Is this a bug?
Anonymous
Not applicable
Author

Not much luck. Here are some errors. The query is in a tOracleInput comonent. The context.TheDate is 'dd-Mon-yyyy' format, including the quotes.

SELECT *
FROM table
WHERE Table.LAST_MOD_DATE
>"+TalendDate.parseDate("dd-MMM-yyyy",context.TheDate)
statistics] connecting to socket on port 3459
connected
Exception in component tOracleInput_2
java.sql.SQLException: ORA-00933: SQL command not properly ended
=================================
SELECT *
FROM table
WHERE Table.LAST_MOD_DATE
> '"+TalendDate.parseDate("dd-MMM-yyyy",context.TheDate)+"'"
Exception in component tOracleInput_2
java.sql.SQLException: ORA-01858: a non-numeric character was found where a numeric was expected
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
Anonymous
Not applicable
Author

print your query to the console in a tJava to debug. Chances are you dont have the format exactly right.
alevy
Specialist
Specialist

If you're using the "date" as part of a SQL statement, it should be a string not a date i.e.
- if your context variable is a string (in the correct format): "SELECT * FROM table WHERE Table.LAST_MOD_DATE>'"+context.TheDate+"'"
- if your context variable is a date: "SELECT * FROM table WHERE Table.LAST_MOD_DATE >'"+TalendDate.formatDate("dd-MMM-yyyy",context.TheDate)+"'"
In both cases, don't forget the '' date-delimiters for Oracle.
Anonymous
Not applicable
Author

Thanks, alevy. Your context variable date version is just what we were looking for. We recognized the SQL string need a date in the form of a string, but wanted the flexibility of setting the context variable using a calendar popup.
It seems date/time pattern in the context variable screens serve no purpose. When I looked at the context variable in the SQL string Talend created I get:
<context variable = "Wed, 9 Mar 2011 12:08:56 -0700"
regardless of what format string was provided. But formatting the date via the TalendDate.formatDate() method works.
alevy
Specialist
Specialist

I believe the pattern only becomes relevant when you try to use tContextLoad or tContextDump - the string is parsed or formatted (respectively) using the pattern defined with the default value. This is basically the same principle as for schema dates i.e. the pattern is a mask only.
There are some issues with context date patterns - see https://community.talend.com/t5/Design-and-Development/how-to-give-column-names-through-context/td-p....