Date fields and compare and get the later date of the fields

I am trying to compare these date fields and compare and get the later date of the fields
Tables are
TABCASER
TABCASER1
EVCASERS
Field
Are
TABCASER1.CASER_no
The dates are to be compared and then get the records with the highest or latest date value.
TABCASER1.CASERRECIEVEDDATE
EVCASERS.FINALEVDATES
EVCASERS.PUBLICATIONDATE
EVCASERS.PUBLICATIONDATE
TABCASER.COMPAREACCEPDATE
I have this code but I am trying to figure out what it all means.
I have several questions.
1.
1.     greatest it is used here to compare right? How do I then output this ? do I store it to a var (coldfusion) ultimately , I wish to send it to a page of records
2.     is it necessary to use todate? And to_date? What does this do?
3.     decode, is this necessary too. What does this do? NULL?
4.     
5.     
6.     when I do get the query results how do I send it to coldsuion and out put to a display.
Someone sent me this code.
is there abetter way of doing this? To compare the dates and store in a var to display. thanks
Here is my code below:
Greatest(
     CASE
          WHEN INSTR(TABCASER1.CASER_no,'-CE') > 0 THEN
     decode(TABCASER1.CASERRECIEVEDDATE,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),TABCASER1.CASERRECIEVEDDATE)
                         WHEN INSTR(TABCASER1.CASER_no,'-ERNIE') > 0 THEN
     decode(EVCASERS.FINALEVDATES,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),EVCASERS.FINALEVDATES)
                         WHEN INSTR(TABCASER1.CASER_no,'-MONIE') > 0 THEN
     decode(EVCASERS.PUBLICATIONDATE,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),EVCASERS.PUBLICATIONDATE)
                         WHEN INSTR(TABCASER1.CASER_no,'-NADINE') > 0 THEN
     decode(EVCASERS.PUBLICATIONDATE,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),EVCASERS.PUBLICATIONDATE)
                         ELSE
     decode(TABCASER.COMPAREACCEPDATE,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),TABCASER.COMPAREACCEPDATE)
                    END
          ,decode(TABCASER.COMPAREACCEPDATE,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),TABCASER.COMPAREACCEPDATE))
          between TO_DATE('#dateformat(form.startDate,"mm/dd/yyyy")#','MM/DD/YYYY') and TO_DATE('#dateformat(form.endDate,"mm/dd/yyyy")#','MM/DD/YYYY')
is there abetter way of doing this? To compare the dates and store in a var to display. thanks

Hi
If you have date datatypes than:
select
greatest(TABCASER1.CASERRECIEVEDDATE, EVCASERS.FINALEVDATES, EVCASERS.PUBLICATIONDATE, EVCASERS.PUBLICATIONDATE, TABCASER.COMPAREACCEPDATE)
from TABCASER, TABCASER1, EVCASERS
where ...-- join and other conditions
1. greatest is good enough
2. to_date creates date dataype from string with the format of format string ('mm/dd/yyyy')
3. decode(a, b, c, d) is a function: if a = b than return c else d. NULL means that there is no data in the cell of the table.
6. to format the date for display use to_char function with format modell as in the to_date function.
Ott Karesz
http://www.trendo-kft.hu

Similar Messages

Maybe you are looking for

  • Target flat file with pipe seperated

    Hi I want to load the data in flat file , i don't see pipe "|" seperation values to create a flat file in this format. how can i achive and how can i also how can i create file name dynamically Thanks

  • Including external Javascript file in JSP- not working on Mozilla Firefox

    I have a JSP page which includes javascript file as below: <script type="text/javascript" src="https://siteAddress/scripts/myJsFile.js"></script> myJsFile.js has a method testFireFox() There is a link on JSP which that calls this method. <a href="#"

  • How to choose which Aperture duplicate photo to keep

    I use Aperture 3.4.5 on an iMac with OS 10.8.4 and, like many others who have written to this community, I have acquired lots of duplicates because some years ago I  moved from iPhoto to Aperture. Those collections are mostly referenced in their orig

  • Add fields in VL10 report - EHN

    Hi , I am supposed to add two fields from Table KNVV-KVGR1/KVGR2 table in to alv report output of VL10/VL10A. I have tried for BADI but none got trigged. Is.Is the any Badi/Exits available or do I need to go for explict/implicit enhancement. Kindly h

  • Library Item Conflict

    Hi. I'd appreciate any help people can offer regarding this problem. I am creating some animations using Flash 8. Some work just fine. Others give me the following message when I try to add a new movie clip: One or more library items exists in docume