Home > Archive > MS SQL Server MSEQ > September 2005 > YTD Last year









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author YTD Last year
Benedikt F

2005-08-31, 8:24 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

2005-09-01, 3:23 am

Try this (not tested)

select *
from Salestable
Where Postingdate >= dateadd(year,datedif
f(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

Benedikt F wrote:

>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.
>
>
>
>

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com