Consulting

Results 1 to 4 of 4

Thread: Solved: Testing current date...

  1. #1
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location

    Solved: Testing current date...

    hi,

    Can anyone advise me how to test if current day is Sunday?

    If yes I'd like to show the data from last week otherwise data from current week.

    So far my code looks like that

    SELECT 
    MNM.DIM_DATE.T_DATE, 
    SUM(MNM.FACT_RCD.COUNT_UNITS) 
    FROM 
    MNM.DIM_DATE, 
    MNM.FACT_RCD 
    WHERE 
    ( MNM.FACT_RCD.T_DATE=MNM.DIM_DATE.T_DATE ) 
    AND 
    ( MNM.DIM_DATE.CURRENT_WEEK='0' ) 
    GROUP BY 
    MNM.DIM_DATE.T_DATE

    And for current week I'm using:
    ( MNM.DIM_DATE.CURRENT_WEEK='C' )

  2. #2
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    what database are you using?

  3. #3
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    I am trying to build a querry in SAP Business Object XI R2

    I've been playing a bit with to_char(sysdate, 'd') with no luck so far.

  4. #4
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    OK finaly I have done it. Code which works for me looks as follows:


     
    SELECT 
      MNM.DIM_DATE.T_DATE, 
      SUM(MNM.FACT_RCD.COUNT_UNITS) 
    FROM 
      MNM.DIM_DATE, 
      MNM.FACT_RCD 
    WHERE 
      ( MNM.FACT_RCD.T_DATE=MNM.DIM_DATE.T_DATE  ) 
      AND  
      ( 
    (to_char(sysdate,'DY')='SUN' 
    AND 
    MNM.DIM_DATE.T_DATE 
    BETWEEN 
    sysdate-8 and sysdate-1) 
    OR 
    (to_char(sysdate,'DY')<>'SUN' 
    AND 
    MNM.DIM_DATE.T_DATE 
    BETWEEN 
    NEXT_DAY(sysdate-8,'Saturday') 
    AND 
    sysdate-1) 
      ) 
    GROUP BY 
      MNM.DIM_DATE.T_DATE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •