Toad World® Forums

Case..When Issue??

Hey all…

I am runnin this statement is a sql query (Oracle) and TDP is not giving the right results:

(Case
When to_char(DATE1,‘yyyymmdd’) = to_char(Subquery.DATE2,‘yyyymmdd’) Then ‘DATES_MATCH’
Else ‘NO_MATCH’
End
)

Here is the output from TDP:

5076.date.png

Any thoughts?

It’s not TDP, it’s your query. Try this instead, if you’re just matching on dates, not times:

(CASE
WHEN TRUNC(DATE1) = TRUNC(SUBQUERY.DATE2) THEN ‘DATES_MATCH’
ELSE ‘NO_MATCH’
END)

There’s no reason to convert the date string to char - that’s what’s causing the confusion. If you were doing your conversion in order to drop the time, TRUNC() is what you should use instead.

Thanks N.B. Trunc worked fine.