or without a functiondeclare @Sample table (PatientId int, AdmissionDate datetime, DischargeDate datetime)insert @Sample select 1, '01-Nov-2009', '05-Nov-2009'union all select 2, '01-Nov-2009', '06-Nov-2009'union all select 3, '02-Nov-2009', '07-Nov-2009'union all select 4, '03-Nov-2009', Nullselect Date, count(*) as [Total Count of Patient for the day]from (select dateadd(day,number,'01-Nov-2009') as date from master..spt_values where type='p' and number<8) a inner join @Sample b on a.Date between AdmissionDate and isnull(DischargeDate, '20991231')group by date
MadhivananFailing to plan is Planning to fail