Re: YTD Last Year again
- From: Hugo Kornelis <hugo@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 05 Sep 2005 22:47:59 +0200
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)
.
- References:
- YTD Last Year again
- From: Benedikt Fridbjornsson
- Re: YTD Last Year again
- From: Hugo Kornelis
- Re: YTD Last Year again
- From: Benedikt F
- YTD Last Year again
- Prev by Date: Re: YTD Last Year again
- Next by Date: Re: How to call talbe/SP from Linked server with out database and user
- Previous by thread: Re: YTD Last Year again
- Next by thread: Re: Join syntax?
- Index(es):