Results 1 to 3 of 3
  1. #1
    soldat452002 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    16

    Sql case multiple conditions

    Hello
    I choose a CASE to look at 3 things:

    TERMINATIONREASONCODE <> COMPLETE
    LICENSE < CURRENT_DATE


    THE HIGHEST DATE OF THESE TWO (DATEEFF > COMPLETIONDATE. Im getting stuck here. Any suggestions I will appreciate


    SELECT
    P.PRODUCERID, C.CONTRACTID, TERMINATIONREASONCODE, to_char(to_date(DateTERM, 'yyyy/mm/dd'), 'mm/dd/yyyy') AS "LIC Expiration", to_char(to_date(E.COMPLETIONDATE, 'yyyy/mm/dd'), 'mm/dd/yyyy') AS "trAINING DATE",
    to_char(to_date(CV.DATEEFF, 'yyyy/mm/dd'), 'mm/dd/yyyy') AS "STATUS EFF",
    CASE
    WHEN CV.TERMINATIONREASONCODE <> 'COMPLETE' THEN 'NOT ELIGIBLE TO SELL'
    WHEN LV.DATETERM < to_char(current_date,'YYYYMMDD') THEN 'NOT ELIGIBLE TO SELL'
    WHEN Cv.DateEff > E.COMPLETIONDATE THEN 'RETURN HIGHEST DATE OF THESE TWO FIELDS'
    ELSE 'ELIGIBLE TO SELL'
    END AS "ELIGIBLE TO SELL STATUS"



    FROM PRODUCER P
    INNER JOIN PRODUCERVER PV ON PV.PRODUCERNO = P.PRODUCERNO
    INNER JOIN Contract C on C.ProducerNo = P.ProducerNo
    INNER JOIN ContractVer CV on CV.ContractNo = C.ContractNo
    LEFT JOIN License L on L.ProducerNo = P.ProducerNo
    LEFT JOIN LicenseVer LV on LV.LicenseNo = L.LicenseNo
    LEFT JOIN Education E on E.ProducerNo = P.ProducerNo
    INNER JOIN JURISDICTION juris ON L.jurisdictionno = juris.jurisdictionno

    WHERE CV.PROSTA = 1 AND CONTRACTTYPE IN ('Selling Agent', 'Producer') AND L.JURISDICTIONNO = E.JURISDICTIONNO
    AND PV.PROSTA = 1
    AND LV.PROSTA = 1
    AND E.BUSINESSUNIT = 'FDD' AND EDUCATIONCATEGORY = 'Product'
    AND AGREEMENT = '2019' AND to_date(cv.DateExp, 'yyyymmdd') > SYSDATE AND to_date(Lv.DateExp, 'yyyymmdd') > SYSDATE


  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    ....wait...is this for Access sql?
    or
    SQL server sql?

  3. #3
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    This looks like T SQL rather than Access.

    Why are you messing around with the dates so much? Simply Cast them into the format you want.
    You certainly shouldn't need two functions to get them into the format you want. The performance hit will be huge.

    Anyway to answer your question

    CASE WHEN Cv.DateEff > E.COMPLETIONDATE THEN Cv.Dateeff ELSE E.COMPLETIONDATE END as HighestDate

    You may want to use >= to determine what happens in the event of a tie.
    Last edited by Minty; 07-27-2018 at 06:43 AM.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Testing for multiple conditions help
    By JHarmon in forum Programming
    Replies: 3
    Last Post: 02-22-2016, 04:16 PM
  2. Replies: 3
    Last Post: 10-27-2014, 07:37 AM
  3. VBA If with multiple conditions
    By Swatskeb in forum Modules
    Replies: 2
    Last Post: 05-22-2014, 04:22 PM
  4. Multiple conditions in Access
    By engr_saud1 in forum Access
    Replies: 1
    Last Post: 04-03-2013, 06:18 AM
  5. Using iif for Multiple Conditions
    By kwilbur in forum Access
    Replies: 5
    Last Post: 12-30-2011, 01:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums