Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with WHERE clause to exclude records

Status
Not open for further replies.

elsenorjose

Technical User
Oct 29, 2003
684
US
I'm not a great SQL coder and I've been asked to modify a query to exclude records that meet the following conditions:

If the projected submission date is NULL
AND
the Actual Submitted date is not null and is before Dec 2010
OR
Actual Approved date is not null and is before Dec 2010

Can someone please help with the syntax as this has been driving me crazy for a few days now.

Thank you
 
Try something like this in the WHERE part of your sql statement

WHERE
(
ProjectedSubmissionDate is null and ActualSubmittedDate < to_date('1-Dec-10','dd-MON-yy')
)
or
(
ActualApprovedDate < to_date('1-Dec-10','dd-MON-yy')
);

regards
Mark
 
Thanks Mark but won't that retrieve records that meet that criteria? I am trying to exclude records that meet that criteria.

Thanks again,
Jose
 
Hi Jose

Sorry I did not read your original emal properly. Try the reverse


WHERE
(
ProjectedSubmissionDate is not null and ActualSubmittedDate > to_date('1-Dec-10','dd-MON-yy')
)
or
(
ActualApprovedDate > to_date('1-Dec-10','dd-MON-yy')
);

If this does not work can I please see your sql statement

regards
Mark
 
Just to be clear, are your requirements to exclude all records where
Code:
(the projected submission date is NULL AND the Actual Submitted date is not null and is before Dec 2010)
OR
(Actual Approved date is not null and is before Dec 2010)
or do you need
Code:
(the projected submission date is NULL)
AND 
((the Actual Submitted date is not null and is before Dec 2010) OR (Actual Approved date is not null and is before Dec 2010))

 
Hi Carp,

The second statement is the correct one. Thank you for the clarifying question.

Mark, thanks for the suggestions. I'll see if I can tweak things a bit.

Thanks,
Jose
 
In that case, I think the following WHERE clause should work:

Code:
WHERE
(projected_submission_date is NOT NULL)
OR
(TRUNC(NVL(Actual_Submitted_date, '1-DEC-2010')) >=  '1-DEC-2010') 
   AND 
  TRUNC(NVL(Actual_Approved_date,'1-DEC-2010')) >= '1-DEC-2010')
It's been a long day and I haven't tested this, but I'm pretty sure it's close to what you are looking for. If not, I'm sure somebody will point out the problem for us.
 
Dima - so good to see you again! It has been far too long.
 
So, it's actually:

Code:
WHERE NOT
(
seq_status_schedule1.sched_date is NULL //Projected Submission
AND
(
seq_status_schedule2.actual_date is not null and seq_status_schedule2.actual_date < to_date('1-Dec-10','dd-MON-yy') //Actual Submitted
) 
OR 
(
seq_status_schedule3.actual_date is not null and seq_status_schedule3.actual_date < to_date('1-Dec-10','dd-MON-yy') //Actual Approved
)
)

What kept throwing me off is we DO want NULL submission dates, just not if they ALSO meet the other 2 criteria. So we couldn't use the following in the query because it effectively throws out all NULL Projected Submission Dates before evaluation the Actual Approved and Submitted dates.

Code:
WHERE
(projected_submission_date is NOT NULL)

Thank you Carp and Mark, though. Between what the two of you provided, I was able to walk through the problem and come up with the right solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top