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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to set continious calender months in SP

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]
AS
BEGIN
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 XX
END


Thanks

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
Go to Top of Page

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 table
EX:49

The above percentage is only for Month of April

I am expecting for every month from APr2012

Output table should be

ward April May June july
EEP 49 50 -- --
Go to Top of Page
   

- Advertisement -