?
Solved

CURRENT_DATE function to show prior month data

Posted on 2012-03-13
5
Medium Priority
?
628 Views
Last Modified: 2012-08-13
How do I use the CURRENT_DATE function in DB2 to pull data for the entire past month on the first day of a new month?
This job runs flawlessly daily with the piece of code below, but on the 1st of the month it returns no results:
ACCT_OPEN_DT >(CURRENT DATE - day(current date) days )

*What do I need to modify to make sure that on the 1st of each month, it still shows the prior month's entire data?
Thanks
0
Comment
Question by:saved4use
[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
5 Comments
 
LVL 4

Expert Comment

by:sathyaram_s
ID: 37717515
--
0
 
LVL 4

Accepted Solution

by:
sathyaram_s earned 2000 total points
ID: 37717523
so, on any day of the month you want results for this month ..

ie, when run on 13th of march, you want everything from 1st of march.

if you run on 1st of april, you want everything from 1st of march to 31st of march.

is my assumption right?

if it is, try


 ACCT_OPEN_DT >(case when day(current date)=1 then (CURRENT DATE - 1 month - 1 day) else (CURRENT DATE - day(current date) days ) end)

Open in new window

0
 
LVL 18

Expert Comment

by:Dave Ford
ID: 37717590
Let's see. CURRENT DATE - day(current date) days  will always return the last day of the previous month. If you wanted to return the FIRST day of the previouos month, you could do:

CURRENT DATE - day(current date) days + 1 day - 1 month

HTH,
DaveSlash
0
 
LVL 18

Expert Comment

by:Dave Ford
ID: 37717595
If you wanted to return the first day of the current month, you'd do this:

CURRENT DATE - day(current date) days + 1 day
0
 

Author Comment

by:saved4use
ID: 37717642
@ sathyaram_s, You are correct, that's exactly what I want.
I've changed my code and will see what happens on 4/1.
Thanks
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 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