Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert Number to Date

enriquemansJul 28 2018 — edited Jul 31 2018

Hello

I wanted to open a new discussion because this is an issue with converting my date fields stored as (INT) '20171005' to date '10/05/2017'

I'm using to_char(to_date(CV.DATEEFF, 'yyyy/mm/dd'), 'mm/dd/yyyy') to convert a number to date but my case statement is not working (See sample).

Any ideas?

     

      

PRODUCERNOTERM CODELIC ExpirationtrAINING DATESTATUS EFFELIGIBLE TO SELL STATUS
15072526734380002COMPLETE10/27/201907/24/201810/05/201710/05/2017
15238183794810000COMPLETE08/31/201807/24/201803/28/201807/24/2018
15294291943970000COMPLETE07/31/202007/23/201806/18/201807/23/2018
15110198533210000COMPLETE01/01/220007/23/201811/18/201711/18/2017
15306619846940000COMPLETE01/31/202007/24/201807/03/201807/24/2018
15037013348650000COMPLETE01/01/220007/24/201808/25/201708/25/2017
15037013348650000COMPLETE08/31/201907/24/201808/25/201708/25/2017

My query:

SELECT

P.PRODUCERNO AS "ID",

TERMINATIONREASONCODE AS "TERM CODE"

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' AND LV.DATETERM > to_char(current_date,'YYYYMMDD')

 

  THEN to_char(greatest(to_char(to_date(CV.DATEEFF, 'yyyy/mm/dd'), 'mm/dd/yyyy'),to_char(to_date(E.COMPLETIONDATE, 'yyyy/mm/dd'), 'mm/dd/yyyy')))

ELSE 'NOT 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 = 'CENT' AND EDUCATIONCATEGORY = 'Product'

  AND AGREEMENT = '2019' AND to_date(cv.DateExp, 'yyyymmdd') > SYSDATE AND to_date(Lv.DateExp, 'yyyymmdd') > SYSDATE

Database Product

Database Product Version

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options

Oracle JDBC driver

11.2.0.4.0

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 28 2018
Added on Jul 28 2018
18 comments
11,859 views