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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Analysis Server and Reporting Services (2005)
 Gettnig Information in One Column
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nokiauk
Starting Member

United Kingdom
9 Posts

Posted - 09/19/2012 :  05:53:51  Show Profile  Reply with Quote
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

United Kingdom
9 Posts

Posted - 09/19/2012 :  06:17:37  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 09/19/2012 :  12:17:10  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000