I'm trying to sort by date in one of the columns but with the code I do, it comes not in order. For example, if I order by descending date, it will come up as 31st October 2022 then the next couple would be 31st May 2024 then 31st May 2023, 31 March 2023, 31st July 2023, 31st January 2023, 31st December 2022. I need to be able to sort by deals which will have a close date nearer the time.
The code is:
select D.ROWID,
'<b style="font-size: large; color:#DC4300;">' || D.CUSTOMER || '</b><br>' ||
'<b>Project Type: </b>' || D.PROJECT || '<br>' ||
'<b>Engagement Type: </b>' || NVL(D.ENGAGEMENT, 'Not Specified') || '<br>' ||
'<b>Opportunity ID: </b>' || NVL(D.OPP_ID, 'Not Specified') || '<br>' ||
--'<b>SF Rep: </b>' || com.COMMERCIAL_MANAGER || '<br>' ||
'<b>CPR: </b>' || D.CPR || '<br>' ||
'<b>VP: </b>' || NVL(D.VP, 'N/A') || '<br>' ||
'<b>Country: </b>' || c.COUNTRY as ENGAGEMENT,
D.CUSTOMER,
com.COMMERCIAL_MANAGER,
D.ARR,
case D.LICENSE
when null then 0
else D.LICENSE
end as LICENSE,
D.SALES_STAGE,
NVL(to_char(D.CLOSE_DATE, 'ddth Month YYYY'), 'Not Specified') as CLOSING_DATE,
'<b>Deal Summary: </b>' || D.COMPLEX_DEMANDS || '<br>' ||
'<b>Approval Date: </b>' || NVL(to_char(D.APPROVALS_DATE, 'ddth Month YYYY'), 'Not Specified') || '<br>' ||
'<b>Drafting Date: </b>' || NVL(to_char(D.DRAFTING_DATE, 'ddth Month YYYY'), 'Not Specified') || '<br><br>' ||
--'<b style="color: #DC4300;">Closing Date: </b>' || NVL(to_char(D.CLOSE_DATE, 'ddth Month YYYY'), 'Not Specified') || '<br><br>' ||
'<b>Customer Facing: </b>' || NVL(D.CUSTOMER_FACING, 'Not Specified') || '<br>' ||
'<b>Tier 3 & 1 Engaged: </b>' || D.TIER3_1 || '<br>' ||
'<b>Closure Risk(s): </b>' || NVL(D.CLOSURE_RISK, 'None') || '<br><br>' ||
'<b>Challenge(s): </b>' || NVL(D.CHALLENGES, 'None') as DEAL_DETAILS,
NVL(D.FBE, 'N/A'),
D.NEXT_STEPS || '<br>' ||
'<b>Contract Standpoint: </b>' || NVL(D.CONTRACT_STANDPOINT, 'N/A')|| '<br>' ||
'<b>Main Contact: </b>' || D.CUSTOMER_CONTACT_NAME || ' - ' || D.CUSTOMER_CONTACT_ROLE as NEXT_STEPS
from TECHCOM D,
COUNTRY_LOOKUP c,
COMMERCIAL_MANAGER_LOOKUP com
where D.country_ID = c.country_ID
and D.COMMERCIAL_MANAGER_ID = com.COMMERCIAL_MANAGER_ID
and D.ARR is not null
and not(D.SALES_STAGE in ('Won', 'Lost'))
ORDER BY D.ARR desc