April 27, 2006 at 1:50 pm
Hello,
I would like to code a rolling date into a prexisting view. Esentially, I want to pull a year's worth of sales records. An example would be:
If today's date is 4/27/06
I would like to see all sales records with a DOCDATE between 4/27/05 and 4/27/06.
Can someone give me an example of how I can code this?
Thank you!
April 27, 2006 at 2:00 pm
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_fa-fz_2c1f.asp
select * from table
where DOCDATE <= DATEADD ( yy , -1, getdate() )
and DOCDATE <= getdate()
April 27, 2006 at 2:01 pm
Thank you!
April 27, 2006 at 2:10 pm
One word of caution: this will get down to the millisecond. Look at Datepart to go about getting just the date...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_da-db_2mic.asp
or Day(), Month() and Year()
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_fa-fz_2c1f.asp
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy