Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > Oracle
|
Oracle General Oracle database discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Oracle section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 21st, 2006, 01:13 PM
Registered User
 
Join Date: Apr 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default compare these date fields and compare and get the

I am trying to compare these date fields and compare and get the later date of the fields
Someone sent me this code.

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.

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('0 1/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')


susanring
 
Old July 24th, 2006, 04:58 PM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

I'm not sure I can answer your question completely, but I can offer a little wisdom:
1. 'GREATEST' is used for comparison, although I'm not sure how well it would work with date parameters. In order to get the greatest date, you may have to do some parsing of the date to strip out the day and month so you could get the highest day from the highest month
2. The TO_DATE function converts a string to a date in the supplied format string - in this case 'MM/DD/YYYY'. It ensures that apples are being compared to apples, as some systems might record May as '5', and others as '05'. For data integrity, is it necessary.
3. 'DECODE' is a sort of if-then-else statement. You can find a good explanation of this and other statements at
http://www.techonthenet.com/oracle/f...ndex_alpha.php.
As far as the code itelf goes, it seems as though there is probably a better way to do it, but I would have to think it through. Also, the number of parameters in the DECODE statement seem to be a little off... I hope this helps.






Similar Threads
Thread Thread Starter Forum Replies Last Post
VB.Net - Access DB - Date compare johneecc VB How-To 4 August 7th, 2008 04:23 PM
compare Neha XSLT 6 July 24th, 2008 08:11 AM
compare nmnm XSLT 3 April 24th, 2007 08:13 AM
Compare two fields from different tables pallone SQL Server 2000 10 March 23rd, 2007 05:14 PM
Compare only the date portion of a datetime field CricketMaster Access 6 April 27th, 2005 01:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.