Groups | Blog | Home
all groups > sql server mseq > august 2005 >

sql server mseq : YTD Last year


Benedikt F
8/31/2005 8:41:04 PM
Hi there, I'd like to ask you for help with following:

I am trying to select YTD for last year in my sales table.

select *
from Salestable
Where Postingdate > "first day of 2004" and
Postingdate < "today last year"


best regards,
Benedikt F.
Computer Department
Iceland Seafood Int.

Steve Kass
9/1/2005 1:20:01 AM
Try this (not tested)

select *
from Salestable
Where Postingdate >= dateadd(year,datediff(year,0,getdate())-1,0)
and Postingdate <= dateadd(year,-1,getdate())

If you need this to follow very specific rules, check whether
this does what you want when there is a leap year issue (on
February 29, is last year's YTD supposed to be the same as it
was on February 28, or should it go through last March 1 and
stay a day ahead for the rest of the year?

Steve Kass
Drew University

[quoted text, click to view]
AddThis Social Bookmark Button