sql greatest,decode,instr. minimize code lines sql

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default sql greatest,decode,instr. minimize code lines sql


    I did not write this code and please excuse me for my beginner questions?


    ? Is there a way to make this code cleaner. Code it where its less lines of
    code?


    ? Can we make the 2 conditions separate rather than a one after the other?
    For ex. Not like this WHEN INSTR(CASESTAB_1.CASENOTXT,'-ll?) > 0 THEN

    decode(CASESTAB_1.RECDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB_1.RECD
    T)

    ? why is it in a pair like this:
    WHEN INSTR(CASESTAB_1.CASENOTXT,'-ll?) > 0 THEN

    decode(CASESTAB_1.RECDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB_1.RECD
    T)
    if the string to find in
    CASESTAB_1.CASENOTXT is independent to comparing date?
    Can the string search and date be separate?

    ? Is the a shorter way of comparing the 4 dates.? Alternatives
    ----------------------------------------------------------------
    Greatest(
    CASE
    WHEN INSTR(CASESTAB_1.CASENOTXT,'-ll?) > 0 THEN

    decode(CASESTAB_1.RECDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB_1.RECD
    T)
    WHEN INSTR(CASESTAB_1.CASENOTXT,'-ss?) > 0 THEN
    decode(ERTAB.FINERDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),ERTAB.FINERDT)
    WHEN INSTR(CASESTAB_1.CASENOTXT,'-dd ') > 0 THEN

    decode(ERTAB.PUBLICATIONDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),ERTAB.PUBLIC
    ATIONDT)
    WHEN INSTR(CASESTAB_1.CASENOTXT,'-ff?) > 0 THEN

    decode(ERTAB.PUBLICATIONDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),ERTAB.PUBLIC
    ATIONDT)
    ELSE
    decode(CASESTAB.CPDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB.CPDT)
    END
    ,decode(CASESTAB.CPDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB.CPDT))

    sql finds the suffixes from CASESTAB_1.CASENOTXT
    AND
    compares dates 4
    ? CASESTAB_1.RECDT
    ? ERTAB.FINERDT
    ? ERTAB.PUBLICATIONDT
    ? CASESTAB.CPDT
    AND GETS THE LATER OF THE 4 DATES.


    1. \find the suffix from caseN0 field/col
    -ll
    --ss
    -dd
    -ff

    CASESTAB_1.CASENOTXT
    2. dates to find the latest date.
    ? CASESTAB_1.RECDT
    ? ERTAB.FINERDT
    ? ERTAB.PUBLICATIONDT
    ? CASESTAB.CPDT

    Using greatest function.
    3. the tables are

    1. ERTAB
    2. CASESTAB
    3. CASESTAB
    :o

    zeny xu Guest

  2. Similar Questions and Discussions

    1. Extra Blank Lines in Code
      :frown; My wife uses Contribute 3 to do some edits and updates for a site that I use Dreamweaver 8 for. When I open a file in Dreamweaver that she...
    2. Blank Lines in program code
      After editing the Home page in Contribute 2 many blank lines are inserted into the page source code. The size of the page keeps increasing...
    3. Maximum Lines of Code
      :o All, I am having a peculiar problem with an <cfif> tag. I get an error message during the execution of the page that tells me the <cfif> tag...
    4. Why is there no error thrown in these 3 lines of code?
      $MyVar=1; if (MyVar ==1){ $var2="abc"; } Notice I left out the "$" in the IF statement. No error. It drops into the statement and sets the...
    5. Need a few lines of code help, will pay!
      I need to figure out how to go through all of the WebControls on a form, find all the ones that are named with a "txt" prefix (ie txtFirstName), and...
  3. #2

    Default Re: sql greatest,decode,instr. minimize code lines sql

    Well, I don't know how much simpler it could get and still do what it is
    designed to do. For example, the statement

    WHEN INSTR(CASESTAB_1.CASENOTXT,'-ll?) > 0 THEN

    decode(CASESTAB_1.RECDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB_1.RECDT
    )

    basically means that if the CASENOTXT column contains '-ll?, then look at the
    RECDT column and if it is NULL, use the date value of '01/01/1900', otherwise
    use the date value in the RECDT column.....

    and so on through the other WHEN clauses in your CASE statement. Is this what
    you are expecting thsi query to do?

    Phil

    paross1 Guest

  4. #3

    Default Re: sql greatest,decode,instr. minimize code lines sql

    thanks,

    yup that is what it is suppose to do find thes suffixes from these columns

    but the date coulms are independant . meaning the date are just to be
    compared and find the greates .
    it does not have to be tied with finding the strings (4 suffixes) .
    so i am wondering why it is
    like
    if you find the suffix then find the date not null .



    i guess i really want to just separte them.


    find the suffixes

    find the dates and compare and find the greates and create a column that have
    all the later dates
    ?

    hope i am expressing it right.

    zeny xu Guest

  5. #4

    Default Re: sql greatest,decode,instr. minimize code lines sql

    Without seeing the entire query, it is hard to speculate why it was written the way that it was.

    Phil
    paross1 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139