Forum Stats

  • 3,733,978 Users
  • 2,246,853 Discussions
  • 7,856,960 Comments

Discussions

Display current week as default first option

Sudhir_Meru
Sudhir_Meru Member Posts: 327
edited May 2015 in SQL

Hi,

In below query am displaying weekending date of a particular year and month. I need suggestion how to display current week ending date as default first row option please suggest me

SELECT SATURDAY D, SATURDAY R FROM

(

WITH    got_month_wanted     AS

(

    SELECT  TO_DATE ( 2015 || ' ' || 'May', 'YYYY MONTH')  AS month_wanted

    FROM    dual

)

,    got_saturday    AS

(

    SELECT  ADD_MONTHS (month_wanted, 1)     AS next_month

    ,       NEXT_DAY ( month_wanted - 1

                     , 'SAT'

                     ) + (7 * (LEVEL - 1))   AS saturday

    FROM    got_month_wanted

    CONNECT BY  LEVEL <= 5  -- No month has more than 5 Saturdays

)

SELECT    saturday

FROM      got_saturday

WHERE     saturday  < next_month

)

Thanks

Sudhir

Sign In or Register to comment.