Title: RE: To_Char Problem

a) Do not convert date fields to characters in a comparison. In your query, use
and a.updated_date =  (select max(updated_date) ...
b) If you absolutely want to create two character strings from a date, and then compare the strings, this is the format to use:

to_char (date1, 'SYYYY/MM/DD HH24:MI:SS') > to_char (date2, 'SYYYY/MM/DD HH24:MI:SS')
or
to_char (date1, 'SYYYYMMDDHH24MISS') > to_char (date2, 'SYYYYMMDDHH24MISS')

> -----Original Message-----
> From: karthikeyan S [mailto:[EMAIL PROTECTED]]
>
> I am using the to_char function in the following query.  But
> it treats the date '31/12/2001' as greater than '01/01/2002'.
> Is there any solution to fix this problem?

>  select distinct(a.default_type_id), a.new_val  
>  from amend_default_value a, amend_default_value b
>  where a.effective_from <= sysdate and
>        a.effective_to    >= sysdate and
>        a.group_id = '942'       and
>        a.default_type_id = b.default_type_id     and
>        to_char(a.updated_date,'dd/mm/yyyy hh:mi:ss') =
>        ( select max(to_char(updated_date,'dd/mm/yyyy hh:mi:ss'))
>        from amend_default_value c
>        where c.effective_from <= sysdate and
>        c.effective_to    >= sysdate and
>        c.group_id = '942' and
>        c.default_type_id = b.default_type_id);

Reply via email to