Re: YTD Last Year again



On Fri, 2 Sep 2005 23:54:11 -0000, Benedikt F wrote:

>Hi Hugo
>
>I have created the Calendar table with the FY column. How can I use your
>Calendar table to select what I need from my salestable.
>
>select *
>from Salestable
>Where Postingdate > "1st of July 2004" and
>Postingdate < "today last year"

Hi Benedikt,

Here is one possible way:

SELECT s.Column1, s.Column2, ...
FROM Salestable AS s
INNER JOIN Calendar AS c
ON c.dt = s.Postingdate
WHERE c.FY = (SELECT FY
FROM Calendar
WHERE dt = DATEADD(year, -1,
DATEADD(day,
DATEDIFF(day,
'20040101',

CURRENT_TIMESTAMP),
'20040101')))
AND s.Postingdate < DATEADD(year, -1,
DATEADD(day,
DATEDIFF(day,
'20040101',
CURRENT_TIMESTAMP),
'20040101'))
(untested)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
.