Posted by David Portas on 09/29/05 20:20
> Well if the design I specified here is not appropriate
If you don't agree then I recommend you read up on database design
practice.
> what if I will have to show it in
> my initial display (again crosstab-style query)?
Like this (I'm assuming calendar quarters. If not, then use a different
calculation or us a Calendar table for the quarters).
SELECT
YEAR(trans_date),
SUM(CASE WHEN MONTH(trans_date) BETWEEN 1 AND 3
THEN trans_amount END),
SUM(CASE WHEN MONTH(trans_date) BETWEEN 4 AND 6
THEN trans_amount END),
SUM(CASE WHEN MONTH(trans_date) BETWEEN 7 AND 9
THEN trans_amount END),
SUM(CASE WHEN MONTH(trans_date) BETWEEN 10 AND 12
THEN trans_amount END)
FROM accounts
GROUP BY YEAR(trans_date) ;
(untested)
--
David Portas
SQL Server MVP
--
[Back to original message]
|