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 |
oasis1
Starting Member
35 Posts |
Posted - 2010-07-11 : 02:00:31
|
I Have the following rollup. I am trying to Divide NS/TA and put it in the final results. How would I write this? I tried a subquery but it won't work. If I try to calculate in the below code it calculates wrong. Mahalo for your help Select case When Grouping(Location) = 1 then 'All Location' Else Location End as MyLocations, case When Grouping(Department) = 1 then 'All Department' Else Department End as MyDepartment, sum(NoShows) as NS, sum(TotalAppts) as TA From dbo.IVR Group by Location, Department with RollupAla Moana Lab 6 34Ala Moana Peds 11 97Ala Moana All Department 17 131Hon Cliinic ED 9 90Hon Cliinic ER 7 90Hon Cliinic All Department 16 180All Location All Department 33 311 |
|
oasis1
Starting Member
35 Posts |
Posted - 2010-07-11 : 02:07:13
|
Got it !!!!Select SQ.*, (SQ.NS/SQ.TA) as Percentage From (Select case When Grouping(Location) = 1 then 'All Location' Else Location End as MyLocations, case When Grouping(Department) = 1 then 'All Department' Else Department End as MyDepartment, sum(NoShows) as NS, sum(TotalAppts) as TA From dbo.IVR Group by Location, Department with Rollup) SQ |
 |
|
|
|
|