Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
mlawton
Starting Member
35 Posts |
Posted - 2011-12-07 : 12:13:35
|
Hi:I am trying to do the following:I have a table with all 2010 data.I want to select 2010 data based on the getdate between +3 days and -3 days.This is what I have so far:SELECT *FROM PriorYR_DataWHERE datepart(dd,date) = datepart(dd,CONVERT(VARCHAR(11),GETDATE()-3,101)) and datepart(mm,date) = datepart(mm,CONVERT(VARCHAR(11),GETDATE()-3,101)) and datepart(yyyy,date) = datepart(yyyy,CONVERT(VARCHAR(11),GETDATE(),101))-1SELECT *FROM PriorYR_DataWHERE datepart(dd,date) = datepart(dd,CONVERT(VARCHAR(11),GETDATE()+3,101)) and datepart(mm,date) = datepart(mm,CONVERT(VARCHAR(11),GETDATE()+3,101)) and datepart(yyyy,date) = datepart(yyyy,CONVERT(VARCHAR(11),GETDATE(),101))-1How can I get all the dates do showup12/10/201012/9/201012/8/201012/7/201012/6/201012/5/201012/4/2010instead of just 12/4/2010 and 12/10/2010? |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-07 : 12:24:58
|
i think you need only this....SELECT *FROM PriorYR_DataWHERE date>= DATEADD(yy,-1,GETDATE()-3)AND date< DATEADD(yy,-1,GETDATE()+4)..... ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
mlawton
Starting Member
35 Posts |
Posted - 2011-12-07 : 12:32:16
|
Thank you!!!That worked perfectly!!! |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|
|