Quote:
Originally Posted by mac4rfree
bingo!!!! that worked well.. i removed to_date function..
|
I am still curious: what is the data type of SELLING_CALENDAR.CURR_YR_ACTUAL_SALES_DATE column? Is it really DATE (as your posts would indicate)? Let me suppose so (in fact I hate guessing, but I want to share more about treating DATEs/VARCHAR2s), otherwise, just ignore the rest or transform it to the real data type of that column.
Did you just blindly removed TO_DATE/TO_CHAR until it returned correct result, or realized that you were extracting day from November, 9th 0008?
Here are some advices:
Do not use only string literals when referencing a DATE (that '08-NOV-09' in WHERE clause - it has VARCHAR data type, hence my second question). Use TO_DATE with proper format mask to convert it to DATE data type explicitly. Now, it (or SELLING_CALENDAR.CURR_YR_ACTUAL_SALES_DATE column - this is tricky thing of implicit conversion - you cannot say which of the two values with different data types in comparison will be converted to the data type of the opposite one; converting the column will prevent use of index on that column, which would slow performance) is converted correctly as it matches NLS_DATE_FORMAT, but it may not be in all sessions for all time. Other side effects may come to play - e.g. truncating of time part when NLS_DATE_FORMAT does not contain it, but keeping it when NLS_DATE_FORMAT will be enhanced with it.
Month abbreviations ('NOV') are dependent on NLS_DATE_LANGUAGE setting. It may work for November for most languages (not all), but be prepared to use e.g. 'DEZ' (Dezember) for December when the NLS_DATE_LANGUAGE will be set to GERMAN. Either use month numbers (11) or specify it in the third parameter of TO_DATE function.
Also be aware that the value of 'D' (day of the week) depends on NLS_TERRITORY setting - if I recall it correctly, week starts on Sunday for NLS_TERRITORY=AMERICA, but on Monday for e.g. most European countries. However I am not aware is would be possible to set it in TO_DATE as NLS_DATE_LANGUAGE - the only way seems to be ALTER SESSION statement.