Solved

CURRENT_DATE function to show prior month data

Posted on 2012-03-13
5
623 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 500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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