Calculate number of days remaining in month use as filter DB2

I want to calculate the number of days remaining in the month and add to a decimal field and then use as a filter in DB2.
Like:

DECLARE @EDate date
SET @EDate  = GETDATE();
SELECT DAY(EOMONTH(@EDate )) AS DaysInMonth

SELECT
a.ACCT_ID,
a.ACCOUNT_NUM,
SUM(a.DYS_PAST_DUE + DaysInMonth) as DPD
FROM schema.table a
WHERE SUM(a.DYS_PAST_DUE + DaysInMonth) >= 60
DCUnitedAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave FordSoftware Developer / Database AdministratorCommented:
SELECT a.ACCT_ID,
       a.ACCOUNT_NUM,
       SUM(a.DYS_PAST_DUE + last_day(current_date) - current_date) as DPD
  FROM schema.table a
 WHERE SUM(a.DYS_PAST_DUE + last_day(current_date) - current_date) >= 60 

Open in new window


HTH,
DaveSlash
0
Dave FordSoftware Developer / Database AdministratorCommented:
Some "flavors" of DB2 don't have a native last_day function. In case you're on one of those, this might help:

CREATE FUNCTION last_day(
    inDate DATE
)
RETURNS DATE
LANGUAGE SQL
modifies sql data

BEGIN
DECLARE resultDate DATE;

-- If the incoming param is NULL, return NULL
IF (inDate IS NULL) THEN
   RETURN null;
End If;

set resultDate = inDate + 1 month - day(inDate + 1 month) days;

-- Return the final output
RETURN resultDate;
END

Open in new window

0
DCUnitedAuthor Commented:
Of course the first suggestion would be the way to go but I guess my DB2 doesn't have the last_day function. The Create Function will not work, I lack the privilege.
Any other ideas?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Dave FordSoftware Developer / Database AdministratorCommented:
I suppose you could "in-line" the logic of the function:

 WHERE SUM(a.DYS_PAST_DUE +  current_date + 1 month - day(current_date + 1 month) days - current_date) >= 60
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tliottaCommented:
The Create Function will not work, I lack the privilege.
If it's a "privilege" problem, that's completely separate from lack of a Last_Day() function. Which problem is it?

Why are you needing to create and run SQL while not having the privilege to create a function? That's like hiring an auto mechanic and leting him use various pliers and screwdrivers, but no wrench sets.
0
DCUnitedAuthor Commented:
Can't help the way the company does things
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DB2

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.