Solved

CURRENT_DATE function to show prior month data

Posted on 2012-03-13
5
602 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
  • 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:daveslash
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:daveslash
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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