SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to set continious calender months in SP
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

satya068
Posting Yak Master

USA
230 Posts

Posted - 11/12/2012 :  10:37:08  Show Profile  Reply with Quote
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

Edited by - satya068 on 11/12/2012 10:51:29

Mike Jackson
Starting Member

37 Posts

Posted - 11/12/2012 :  10:50:43  Show Profile  Reply with Quote
You might want to post some example data as well as expected result.

Mike
Go to Top of Page

satya068
Posting Yak Master

USA
230 Posts

Posted - 11/12/2012 :  10:55:24  Show Profile  Reply with Quote
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 -- --

Edited by - satya068 on 11/12/2012 11:00:56
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000