Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

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

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: DB2 QUERY to find the 3rd working day for a month
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10257
Location: italy

PostPosted: Sat Apr 12, 2008 3:45 pm    Post subject: Reply to: [b] DB2 QUERY[/b] to find the [b]3rd working day f
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    Post subject: Re: [b] DB2 QUERY[/b] to find the [b]3rd working day for a m
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10257
Location: italy

PostPosted: Sat Apr 12, 2008 3:56 pm    Post subject: Reply to: DB2 QUERY to find the 3rd working day for a month
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    Post subject:
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    Post subject:
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    Post subject: Reply to: DB2 QUERY to find the 3rd working day for a month
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts find RACF group for access to spooled... jzhardy JCL & VSAM 1 Mon May 08, 2017 11:46 am
No new posts To find out size allocated to a seque... ashek15 JCL & VSAM 15 Thu Apr 27, 2017 9:42 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SORT to append Month and YEAR in MMYY... tisamf DFSORT/ICETOOL 1 Wed Mar 08, 2017 4:46 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us