You are here: Re: Horizotal to Vertical Display « MsSQL Server « IT news, forums, messages
Re: Horizotal to Vertical Display

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация