How to determine weeks which are between two month ? Heeeeeeelp !!!!

  • Hi All,

    I need your help.

    I want to determine the weeks which are between two months and How many days are in the Month M and How many days are in the month M+1.

    I found what I need in an oracle forum: http://www.developpez.net/forums/d908298/bases-donnees/oracle/sql/nb-jours-semaine-cheval-2-mois/

    I found the sql script in a Oracle forum but I don't know to translate it into T-SQL.

    This is the URL where i found the Oracle Script. It s a french forum :)) : http://www.developpez.net/forums/d908298/bases-donnees/oracle/sql/nb-jours-semaine-cheval-2-mois/

    And this the Oracle script:

    WITH cal AS

    (

    SELECT date '2010-01-01' + level -1 AS dt

    FROM dual

    connect BY level <= 365

    )

    , sr AS

    (

    SELECT to_char(dt, 'yyyy-mm') AS mois ,

    to_char(dt, 'iyyy"W"iw') AS iweek,

    count(*) AS nb_jours,

    count(*) over(partition BY to_char(dt, 'iyyy"W"iw')) AS nb_mois

    FROM cal

    GROUP BY to_char(dt, 'yyyy-mm'),

    to_char(dt, 'iyyy"W"iw')

    )

    SELECT *

    FROM sr

    WHERE nb_mois = 2

    ORDER BY mois ASC, iweek ASC;

    MOIS IWEEK NB_DAY NB_MONTH

    ------- ------- ---------- ----------

    2010-03 2010W13 3 2

    2010-04 2010W13 4 2

    2010-04 2010W17 5 2

    2010-05 2010W17 2 2

    2010-05 2010W22 1 2

    2010-06 2010W22 6 2

    2010-06 2010W26 3 2

    2010-07 2010W26 4 2

    2010-07 2010W30 6 2

    2010-08 2010W30 1 2

    2010-08 2010W35 2 2

    2010-09 2010W35 5 2

    2010-09 2010W39 4 2

    2010-10 2010W39 3 2

    2010-11 2010W48 2 2

    2010-12 2010W48 5 2

    I am waiting your answer.

  • This is actually a duplicate post. Please provide any answers on the original post which, BTW, has been updated with even more clarification than what is on this post. Thanks, folks.

    Here's the original post...

    http://www.sqlservercentral.com/Forums/Topic1389062-391-1.aspx

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply