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: 10210
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: 10210
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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts find particular member name in PDS us... ravi243 CLIST & REXX 10 Mon Dec 19, 2016 6:44 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am


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