LAST_DAY function in db2

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
sshettar
Premium Member
Premium Member
Posts: 264
Joined: Thu Nov 30, 2006 10:37 am

LAST_DAY function in db2

Post by sshettar »

Hi All,

I have this field which needs to get the month end date of a given date field . i am populating a db2 table. I know db2 does have a function LAST_DAY which would give this result, i tried using this function on Advanced Query Tool , but i'm getting the following error

42884(-440)[IBM][CLI Driver][DB2/AIX64] SQL0440N No authorized routine named "LAST_DAY" of type "FUNCTION" having compatible arguments was found. SQLSTATE=42884
(0.19 secs)

Do not know as to why i'm getting this error.

any help in achieving this task would be of great help

Thanks in advance
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Re: LAST_DAY function in db2

Post by Sainath.Srinivasan »

sshettar wrote: No authorized routine named "LAST_DAY" of type "FUNCTION" having compatible arguments was found. SQLSTATE=42884
Appears issue with the arguments passed.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

First person you should take this to, IMHO, is your DBA. That or Google for examples of the proper syntax.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sshettar
Premium Member
Premium Member
Posts: 264
Joined: Thu Nov 30, 2006 10:37 am

Post by sshettar »

I did check with the DBA and he said that the version of DB2 we are using doesnt support the function LAST_DAY.
is there any other way to get the month end date of a given date ?

any helo is highly appreciated

Thanks in advance
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sorry, my helicopter is in the shop. :wink:

Check this thread: viewtopic.php?t=115051
-craig

"You can never have too many knives" -- Logan Nine Fingers
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

probably this topic can give you a good start

viewtopic.php?p=338077&highlight=#338077

apart from that you need to add 1 to the month and if its 12 add 1 to year and hard code 01 as month.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
Grace J.
Participant
Posts: 22
Joined: Mon Nov 03, 2008 5:34 am

Post by Grace J. »

Try this, select (given_date +1 month -day(given_date) day) lastday from tablename ;
laknar
Participant
Posts: 162
Joined: Thu Apr 26, 2007 5:59 am
Location: Chennai

Post by laknar »

select DATE('given_date') +1 month -day(DATE('given_date')) as lastday from tablename
sshettar
Premium Member
Premium Member
Posts: 264
Joined: Thu Nov 30, 2006 10:37 am

Post by sshettar »

Thanks Grace and laknar!!!!

the command worked for me .

Thanks you once again. i'm marking this topic as resolved
Post Reply