Solved

Oracle SQL - Dynamic Dates

Posted on 2011-03-24
4
352 Views
Last Modified: 2012-05-11
Looking for SQL to create dynamic dates, so that it always pulls from December 1 of prior year to the current date.

Example (if run today):
Select * from my_table where my_date between '12/1/2010' and '3/24/2011'

Need this part to be dynamic: '12/1/2010' and '3/24/2011'
0
Comment
Question by:carsRST
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 35208660
elect * from my_table where my_date
between add_months(trunc(sysdate,'yyyy') ,-1) and trunc(sysdate)

0
 
LVL 74

Expert Comment

by:sdstuber
ID: 35208669
note the "between" will exclude all data for today unless my_date is for midnight  00:00:00


if you want to include today, try one of these clauses instead

my_date between add_months(trunc(sysdate,'yyyy') ,-1) and trunc(sysdate)+1 - 1/86400


or

my_date >=  add_months(trunc(sysdate,'yyyy') ,-1) and my_date < trunc(sysdate)+1



0
 
LVL 16

Author Closing Comment

by:carsRST
ID: 35208670
You're a good man!

Thanks.
0
 
LVL 16

Author Comment

by:carsRST
ID: 35208679
>>note the "between" will exclude all data for today unless my_date is for midnight  00:00:00

Actually, I really need as of the previous day anyway.  works out perfectly.

Thank you!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
add more rows to hierarchy 3 48
minium over 4 numeric columns for each row in oracle 2 56
Pivoting oracle table 9 92
RMAN-06100 when restoring backupset 4 13
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question