ganesaselvam_thylak (9/1/2009)
hi Lynn,Thanks for your query, can u explain the query?
select getdate(), dateadd(wk, datediff(wk, 0, getdate()) - 1, 0), dateadd(wk, datediff(wk, 0, getdate()) - 1, 0) + 4
Break that query down into parts and it becomes easy to understand what is goign on. Also if you read the Larson article I referenced a efw posts up it becomes quite clear as well.
Select Getdate() we know what this does, no? IF not it's in BOL
sELECT dateadd(wk, datediff(wk, 0, getdate()) - 1, 0) find the 1st day of last week depending on what your system determines as the 1st day of the week.
The third column just adds 4 days to the previous column.
Again have a look at the article and I think it will become quite clear. Greg explains it in much better detail than I have here. Also see Michael Valentine Jones' replies on using the earliest SQL Server date instead of 0 as Larsen does... It's a good idea if you'll ever need to deal with dates ion those ranges.
Hope that clears some things up.
-Luke.