Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2011
    Posts
    82

    Unanswered: Monday to Sunday - No Data for a Sunday being displayed

    Hello

    I have written a piece of SQL which I thought was wokring fine. I wanted to show all data for the current week from Monday - Sunday

    I wanted to pick up all data from Monday 00:00:01 to Sunday 23:59:59 and then when the data runs again on the next Monday, a completley new set of data starts to be loaded in

    On the off chance I have come into work today and realise that no data is being diaplyed, and today is a Sunday

    Could someone kindly take a look at my SQL and kindly tell me where I am going wrong

    I know for a fact that my SQL will pick up data as soon as it hits 00:00:01 tonight

    I really want my SQL to pick up data for a Sunday

    BETWEEN DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0) AND DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 6)

    Many Thanks
    Helen

  2. #2
    Join Date
    Apr 2012
    Posts
    213
    Hi,

    Try:

    Code:
    where
        DATEDIFF(DAY,
                 DATEADD(day, DATEDIFF(day, 0, GETDATE()), 7 - DATEPART(weekday, GETDATE())), 
                 MyColumn)  between -6 and 0
    Hope this helps.

Posting Permissions

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