Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Jun 2011
    Posts
    188
    Thanks
    62
    Thanked 0 Times in 0 Posts

    Weekly calander base sqlquery

    Hi experts!

    I am trying to make a weekly base query which from Thursday to Wednesday please correct what I am doing wrong

    Code:
    SELECT 
    DATEADD(dd, -(DATEPART(dw, START_DATETIME)-1), START_DATETIME) [WeekStart],
    
    DATEADD(dd, 11-(DATEPART(dw, START_DATETIME)), START_DATETIME) [WeekEnd],
    DATEPART(wk,START_DATETIME) AS WeekNumber,SUM(VOL1) WvOL,SUM(VOL2)GVOL
    FROM TEST_TABLE WHERE CONVERT(DATETIME,CONVERT(VARCHAR,[START_DATETIME],101)) >= '1/1/2013'
    			AND CONVERT(DATETIME,CONVERT(VARCHAR,[START_DATETIME],101)) <= '8/28/2013'
    GROUP BY DATEPART(wk,START_DATETIME),DATEADD(dd, 11-(DATEPART(dw, START_DATETIME)), START_DATETIME),DATEADD(dd, -(DATEPART(dw, START_DATETIME)-1), START_DATETIME)
    ORDER BY
    DATEADD(dd, 11-(DATEPART(dw, START_DATETIME)), START_DATETIME)

    Thanks
    fkh
    Last edited by farrukh; 2013-08-28 at 15:29.

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts
    The thread Week Starts on Friday may provide you some insight even though you wish to start the week on Thursday.
    Wendell

Posting Permissions

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