We help IT Professionals succeed at work.
Get Started
Troubleshooting Question

Question with Oracle / Coldfusion SQL Query based on max date

Last Modified: 2021-03-08
Hi All!! Im having trouble with a query that Im hoping to get some help on. I have a very simple table, and all Im trying to do is get the records returned if the max date is 30 days older than the current (todays) date. Except that I don't want any of the records if one is within the 30 days. So in the table, I have two records for "MIPR_ID = 2778" . One has a date of 2/19/2021 and the other has a date of 9/16/2020. So I don't want either record returned because one record is within the current 30 days. However, if both records had a date more than 30 days old, I would want both records returned. Below is my query, but it doesnt work and I am at a loss. Any help would be greatly appreciated.

<cfset doccurrentdate="#DateFormat(Now(), 'dd-mmm-yyyy')#" />
<cfset docprevdate="#doccurrentdate#" -30 />

<cfquery name="CcomInput" datasource="MOracle">
select distinct mipr_id, id,
max(last_remark_update) as lastdate
from MCA.unob_remarks
where max(last_remark_update) < '#dateformat(docprevdate, 'dd-mmm-yyyy')#'
and unob_remarks.mipr_id = '2778'    
GROUP BY unob_remarks.mipr_id, unob_remarks.id

Watch Question
Data Warehouse / Database Architect
This problem has been solved!
Unlock 1 Answer and 16 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE