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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case expression in the WHERE clause of a delete statment

Status
Not open for further replies.

sa0309

Programmer
Apr 5, 2010
45
US
I have a delete statement:

My original Delete:
DELETE FROM TableName A
WHERE SCHED_SURGERY_TM >= TRUNC(sysdate)-90


Now I need to delete based upon either START_TM or SCHED_SURGERY_TM :
DELETE FROM TableName A
WHERE
( case
when A.START_TM IS not NULL THEN
A.START_TM >= TRUNC(sysdate)-90
else
A.SCHED_SURGERY_TM >= TRUNC(sysdate)- 90
end
)
What I'm trying to accomplish is use START_TM ( if not null ) else use SCHED_SURGERY_TM and delete the last 90 days of data. I know this example doesn't work. Any suggestions on how this can be accomplished or can it?

Thank you.
 
How about...
Code:
WHERE 
( case
when [b]NOT[/b] A.START_TM [b]IS NULL[/b] THEN 
A.START_TM >= TRUNC(sysdate)-90 
else 
A.SCHED_SURGERY_TM >= TRUNC(sysdate)- 90
end 
)


Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
 
Not using case but what about
Code:
WHERE (A.START_TM IS not NULL AND A.START_TM >= TRUNC(sysdate)-90)
OR
(A.START_TM IS NULL AND A.SCHED_SURGERY_TM >= TRUNC(sysdate)- 90)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top