all groups > sql server mseq > september 2005 >
You're in the

sql server mseq

group:

YTD Last Year again


YTD Last Year again Benedikt Fridbjornsson
9/2/2005 12:00:00 AM
sql server mseq:
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. Our accounting
year is from 1st of July to 30 June.



select *
from Salestable
Where Postingdate > "1st of July 2004" and
Postingdate < "today last year"


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

Re: YTD Last Year again Hugo Kornelis
9/2/2005 10:21:10 PM
[quoted text, click to view]

Hi Benedikt,

The easiest way to get this done is to use a calendar table.

http://www.aspfaq.com/show.asp?id=2519

Best, Hugo
--

Re: YTD Last Year again Benedikt F
9/2/2005 11:54:11 PM
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"


[quoted text, click to view]

Re: YTD Last Year again Hugo Kornelis
9/5/2005 10:47:59 PM
[quoted text, click to view]

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

AddThis Social Bookmark Button