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.
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 TDGROUP BYTD.MgtAreaThis 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) ENDFROM#TenantDetails as TDGROUP BYTD.MgtArea |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-19 : 12:17:10
|
i think you need just thisSELECT TD.MGTAREA, [Avg Age 01/04/2000] = AVG(TD.AgeIn2000) FROM #TenantDetails as TDGROUP BY TD.MgtArea ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|