
			with busyCount as (
				with curD as (select cast(dbo.tzGetDate() AS date)::timestamp(3) as curDate)
				select
					EvnSection.LpuSectionWard_id as LpuSectionWard_id,
					count(EvnSection.EvnSection_id) as busy
				from
					v_EvnSection EvnSection
					LEFT JOIN v_EvnPS EvnPS on EvnPS.EvnPS_id = EvnSection.EvnSection_pid
				where
					EvnSection.Lpu_id = '13101214'
					and EvnSection.LpuSection_id = '99560025462'
					and EvnPS.EvnPS_id is not null
					and EvnSection.LpuSectionWard_id is not null
					and cast(EvnSection_setDate as DATE) <= (select curDate from curD)
					and (EvnSection_disDate > (select curDate from curD) or EvnSection_disDate is null)
				group by
					EvnSection.LpuSectionWard_id
			)
			select
				LSW.LpuSectionWard_id as "LpuSectionWard_id",
				LSW.LpuSection_id as "LpuSection_id",
				LSW.LpuSectionWard_Name as "LpuSectionWard_Name",
				LSW.LpuWardType_id as "LpuWardType_id",
				LSW.Sex_id as "Sex_id"
			from
				v_LpuSectionWard LSW
				left join busyCount on busyCount.LpuSectionWard_id = LSW.LpuSectionWard_id
			where
				LSW.LpuSection_id = '99560025462'
				and (cast('2022-01-22' as date) between cast(LSW.LpuSectionWard_setDate as date) and cast(coalesce(LSW.LpuSectionWard_disDate,'2022-01-22') as date))
				and (LSW.LpuSectionWard_BedCount - LSW.LpuSectionWard_BedRepair - coalesce(busyCount.busy, 0)) > 0
			order by
				LSW.LpuSectionWard_Name
		
