IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

DB2 QUERY to find the 3rd working day for a month


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
padmavathi

New User


Joined: 25 Mar 2008
Posts: 6
Location: chennai

PostPosted: Sat Apr 12, 2008 3:08 pm
Reply with quote

Hi
I need a query to calculate the 3rd working day for a month excluding the saturdays and sundays for a month..
can any one help me for executing this.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sat Apr 12, 2008 3:45 pm
Reply with quote

Do You have an idea of the algorithm to be used ??

I am asking in order to understand how much detail You need in the explanation

by the way it' s rather complicated to implement as a SQL/db2 query

also what if an holiday falls in the middle ...
may first, labor day is an holiday for example
Back to top
View user's profile Send private message
padmavathi

New User


Joined: 25 Mar 2008
Posts: 6
Location: chennai

PostPosted: Sat Apr 12, 2008 3:46 pm
Reply with quote

Hi
a change in my question.I need a query to calculate the 3rd last working day for a month excluding the saturdays and sundays for a month..
can any one help me for executing this.[/quote]
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sat Apr 12, 2008 3:56 pm
Reply with quote

it does not make any difference between the fisrt or the last...
can You reply to my previous post please

what if it cannot be done with a query,
but You need to write a program/subroutine/or an udf ???
Back to top
View user's profile Send private message
padmavathi

New User


Joined: 25 Mar 2008
Posts: 6
Location: chennai

PostPosted: Sat Apr 12, 2008 5:26 pm
Reply with quote

No necessity of considering the holidays other than saturdays and sundays..i need only 3 days before last working day. i will have the end date of that month.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Tue Apr 15, 2008 7:51 pm
Reply with quote

Try this

Code:
CREATE FUNCTION TARGETDATE (MDATE DATE)
LANGUAGE SQL                           
CONTAINS SQL                           
NO EXTERNAL ACTION                     
DETERMINISTIC                         
RETURNS DATE                           
RETURN                                 
LAST_DAY(MDATE) -                     
(CASE DAYOFWEEK(LAST_DAY(MDATE))       
   WHEN 1 THEN 5                       
   WHEN 2 THEN 5                       
   WHEN 3 THEN 5                       
   WHEN 4 THEN 5                       
   WHEN 5 THEN 3                       
   WHEN 6 THEN 3                       
   WHEN 7 THEN 4 END) DAYS;           



Code:
WS-DATE CAN BE ANY DATE IN THE MONTH.                                   
    SELECT TARGETDATE(DATE(:WS-DATE)) INTO :WS-TARGET FROM      SYSIBM.SYSDUMMY1
OR SET :WS-TARGET = TARGETDATE(DATE(:WS-DATE))                         
 WS-DATE = '2008-01-01' WS-TARGET = '2008-01-28'                       
 WS-DATE = '2008-02-01' WS-TARGET = '2008-02-26'                       
 WS-DATE = '2008-03-01' WS-TARGET = '2008-03-26'                       
 WS-DATE = '2008-04-01' WS-TARGET = '2008-04-25'                       
 WS-DATE = '2008-05-01' WS-TARGET = '2008-05-27'                       
 WS-DATE = '2008-06-01' WS-TARGET = '2008-06-25'                       
 WS-DATE = '2008-07-01' WS-TARGET = '2008-07-28'                       
 WS-DATE = '2008-08-01' WS-TARGET = '2008-08-26'                       
 WS-DATE = '2008-09-01' WS-TARGET = '2008-09-25'                       
 WS-DATE = '2008-10-01' WS-TARGET = '2008-10-28'                       
 WS-DATE = '2008-11-01' WS-TARGET = '2008-11-25'                       
 WS-DATE = '2008-12-01' WS-TARGET = '2008-12-26'                       
Back to top
View user's profile Send private message
padmavathi

New User


Joined: 25 Mar 2008
Posts: 6
Location: chennai

PostPosted: Mon Apr 21, 2008 8:32 pm
Reply with quote

hi
thank you..
its working fine icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Populate last day of the Month in MMD... SYNCSORT 2
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts RC query -Time column CA Products 3
No new posts PD not working for unsigned packed JO... DFSORT/ICETOOL 5
Search our Forums:

Back to Top