Home > SQL Development > [Transact-SQL] DatePart Calculations

[Transact-SQL] DatePart Calculations



I have to create a report that runs every Monday, but pulls data from the previous Sunday to Saturday.



For example: The report ran on Feb 25th, but pulled data from Feb 17th(Sun) to Feb 23rd(Sat).



This is what I have so far, but can't figure out what I need:


Code:



SELECT *
FROM table1
WHERE date >= convert(datetime,convert(varchar(30),getdate() - DATEPART(dw,getdate()), 112) +2)






Can anyone help me with the correct query?



Thanks,

Ninel

    
Guest


try something like this:


sql Code:
















Original
- sql Code


  1. SELECT *
  2. FROM tbl_TableName
  3. WHERE date_field >= dateadd(d,-8,getdate())
  4. AND date_field <= dateadd(d,-2,getdate())



Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved