Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Analysis Server and Reporting Services (2005)
 Gettnig Information in One Column

Author  Topic 

nokiauk
Starting Member

9 Posts

Posted - 2012-09-19 : 05:53:51
Hi

Currently I have got my SQL code:

SELECT

TD.MGTAREA,
CASE WHEN TD.MGTAREA IN ('AMEN','WCAM') THEN AVG(TD.AgeIn2000) END AS [Avg Age 01/04/2000],
CASE WHEN TD.MGTAREA IN ('VS','WCVS') THEN AVG(TD.AgeIn2000) END AS [Avg Age 01/04/2000],
CASE WHEN TD.MGTAREA IN ('SHBAS','WCSHB','SHFULL', 'WCSHF') THEN AVG(TD.AgeIn2000) END AS [Avg Age 01/04/2000]

FROM

#TenantDetails as TD

GROUP BY

TD.MgtArea

This is the result:



Is it possible to just have one Ave Age 01/04/2000 column showing all values for the MgtArea.

Thanks

nokiauk
Starting Member

9 Posts

Posted - 2012-09-19 : 06:17:37
Think I've not got it: Revised Code:

SELECT

TD.MGTAREA, [Avg Age 01/04/2000] =
CASE WHEN TD.MGTAREA IN ('AMEN','WCAM') THEN AVG(TD.AgeIn2000)
WHEN TD.MGTAREA IN ('VS','WCVS') THEN AVG(TD.AgeIn2000)
WHEN TD.MGTAREA IN ('SHBAS','WCSHB','SHFULL', 'WCSHF') THEN AVG(TD.AgeIn2000)
END

FROM

#TenantDetails as TD

GROUP BY

TD.MgtArea
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-19 : 12:17:10
i think you need just this


SELECT TD.MGTAREA, [Avg Age 01/04/2000] = AVG(TD.AgeIn2000)
FROM #TenantDetails as TD
GROUP BY TD.MgtArea


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -