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!

Case Statement In a Where Clause.

797273Sep 11 2010 — edited Sep 13 2010
OK, I need to find out if this is possible. Basically if it is the first day of the month, I need the code to look back to the prior month, else it should show the current month. I am getting errors ranging from missing the right parentheses to missing keyword. If there is a better way to do this, I am open to suggestions, I appreciate any and all help.


Select
Acct,
Completetion_Date

From TableName
Where Status = 'A'
And Completion_Date =
(Case
When To_char(sysdate,'dd') = '01' Then Completion_Date Between Add_Months(Trunc(Sysdate, 'MM'),-1) And Trunc(Sysdate,'MM')-1 --prior month
Else
Completion_Date Between Trunc(Sysdate, 'MM') And Add_Months(Trunc(Sysdate,'MM')-1,+1) --current month
End)

Thanks Brian

Edited by: user8698740 on Sep 11, 2010 6:16 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 11 2010
Added on Sep 11 2010
5 comments
1,188 views