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: 10457
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: 10457
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 How to force a select query to abend neo4u DB2 4 Mon Apr 23, 2018 1:36 pm
No new posts Find & Replace string in CA-SORT mrgnndhmk CA Products 1 Fri Mar 30, 2018 12:58 am
No new posts Query to compare 2 values of 1 column... Poha Eater DB2 13 Fri Mar 09, 2018 10:45 am
No new posts How to replace the below query? pkmurali DB2 12 Tue Feb 27, 2018 9:51 pm
No new posts Find a string in PS file opened in br... mukkas CLIST & REXX 3 Sat Feb 24, 2018 2:15 pm

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