
November 7th, 2012, 01:12 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 2
Time spent in forums: 20 m 28 sec
Reputation Power: 0
|
|
|
Generating Percentage compliance for each month in a new table
Hello,
When i run the below script is am getting the total percentage from 2012-Apr-01 to currentdate, which is Numerator/Denomeatorx100
Can i know how to generate the percentage for each month from APR2012 TO CURRENT againaist each ward into a new table?
Ward Apr 12 May 12 June 12 July 12…
APP 60%
APB 55%
APM 49%
…
SELECT xx.EDD/(select CAST(count(*) as Int) as "TEP" from
(select admission_number, admission_date, discharge_date ,estimated_discharge_date, create_date, DIM_IP_ADMISSIONS.update_date,CURRENT_WARD_CODE,cu rrent_flag
from DIM_IP_ADMISSIONS
WHERE DATEDIFF(YEAR,person_date_of_birth,ADMISSION_DATE) >=65
and person_deceased = 'N'
and visit_status in ('A', 'D')
and CURRENT_WARD_CODE in ('APP','APB''APM','MTR','MFT')
and admission_date between '2012-04-01 00:00:00.000' and GETDATE()
and current_flag ='y') as y
)
FROM
(select CAST(count(*) as Int)*100 as "EDD" from
(select DISTINCT A.ADMISSION_NUMBER
from DIM_IP_ADMISSIONS A
INNER JOIN
(select * from DIM_IP_ADMISSIONS B
where B.current_flag ='Y') B
ON A.ADMISSION_NUMBER =B.ADMISSION_NUMBER
WHERE
A.estimated_discharge_date IS NOT NULL
and isnull(A.update_date,A.create_date)<= A.admission_date + 2
and DATEDIFF(YEAR,A.person_date_of_birth,A.ADMISSION_D ATE) >=65
and A.person_deceased = 'N'
and A.visit_status in ('A', 'D')
and A.CURRENT_WARD_CODE in ('APP','APB''APM','MTR','MFT')
and A.admission_date between '2012-04-01 00:00:00.000' and getdate()) as x) as xx
|