Good one..
First 2 queries are non-sargable. i would like to write the first 2 queries in a different way.
Find records which date falls somewhere inside the current week.
where TransDate >=
dateadd( week, datediff( week, 0, getdate() ), 0 )
Find records which date occurred last week.
where TransDate >= dateadd( week, datediff( week, 0, getdate() ) - 1, 0 ) and
Transdate < dateadd( week, datediff( week, 0, getdate() ), 0 )
I have an article on datetime.
http://beyondrelational.com/blogs/community/archive/2010/09/30/top-10-questions-on-datetime-asked-in-forums.aspx
commented on Jun 15 2011 2:48AM