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 |
satya068
Posting Yak Master
233 Posts |
Posted - 2012-11-12 : 10:37:08
|
Hello,This is my SP created for getting the percentage of the ward for the month of april, I need this to repeat every month from April2012 and should load into the table.How to set the dates in SP to get the percentage for every month?ALTER PROCEDURE [dbo].[sp_EstimatedDischargeDate] ASBEGIN SET NOCOUNT ON; SELECT XX.EDD/(select CAST(count(*) as Int) as "TEP" from (select * from (select DISTINCT admission_number,admission_date, discharge_date ,estimated_discharge_date, create_date, DIM_BA_ADM.update_date,CURRENT_WARD_CODE,current_flag,ROW_NUMBER() OVER(PARTITION BY admission_number ORDER BY admission_date) AS TEP from DIM_BA_ADM WHERE DATEDIFF(YEAR,person_date_of_birth,ADMISSION_DATE) >=65 and CURRENT_WARD_CODE in ('8548*EEP') and admission_date between '2012-06-01 00:00:00.000' and '2012-06-30 00:00:00.000')S WHERE TEP=1) as y ) FROM (select CAST(count(*) as Int)*100 as "EDD" from (select DISTINCT A.ADMISSION_NUMBER from DIM_BA_ADM A INNER JOIN (select * from DIM_BA_ADM B where B.current_flag ='Y') B ON A.ADMISSION_NUMBER =B.ADMISSION_NUMBER WHERE A.CURRENT_WARD_CODE in ('8548*EEP') and A.admission_date between '2012-06-01 00:00:00.000' and '2012-06-30 00:00:00.000') as X) as XXENDThanks |
|
Mike Jackson
Starting Member
37 Posts |
Posted - 2012-11-12 : 10:50:43
|
You might want to post some example data as well as expected result.Mike |
|
|
satya068
Posting Yak Master
233 Posts |
Posted - 2012-11-12 : 10:55:24
|
Thanks for you reply mike,The above script will calculates the percentage and writes into a tableEX:49The above percentage is only for Month of AprilI am expecting for every month from APr2012Output table should beward April May June julyEEP 49 50 -- -- |
|
|
|
|
|
|
|