Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 10327
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: 10327
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 HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Fetch Previous month & year in MM... girishb2 DFSORT/ICETOOL 3 Thu Sep 21, 2017 9:54 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts LIBDEF not working in called proc packerm CLIST & REXX 0 Fri Sep 15, 2017 7:22 pm
No new posts Working with hex values in Filemanage... Emile Straker IBM Tools 0 Tue Sep 12, 2017 1:42 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us