
SELECT
 count(  * ) AS cnt 
from
-- from
         vc.v_VaccinationPlan vp
         left join vc.v_VaccinationData vd on vd.VaccinationPlan_id = vp.VaccinationPlan_id
         left join v_EvnVaccination ve on ve.EvnVaccination_id = vd.EvnVaccination_id
         left join vc.v_Vaccination v on v.Vaccination_id = vd.Vaccination_id
         left join dbo.v_PersonState ps on ps.Person_id = vp.Person_id
         left outer join dbo.v_PersonCardState card
                         on card.Person_id = vp.Person_id and card.LpuAttachType_id = 1
         left join dbo.v_Job j on j.Job_id = ps.Job_id
         left join dbo.v_Org org on org.Org_id = j.Org_id
         left join dbo.v_Lpu lpu on lpu.Lpu_id = ps.Lpu_id
         left join dbo.v_LpuRegion rg on card.LpuRegion_id = rg.LpuRegion_id

             -- Наличие на складе МО
         left join vc.v_VaccinationTypePrep vtp
                   on vtp.VaccinationType_id = v.VaccinationType_id -- Препараты для вакцинации
         left join rls.PREP pr on pr.Prep_id = vtp.Prep_id -- Препараты
         left join rls.Drug dr on dr.DrugPrep_id = pr.Prep_id
         left join dbo.v_MedService md
                   on md.Lpu_id = lpu.Lpu_id and md.MedServiceType_id = 31 -- мед сервис - кабинет вакцинации
         left join dbo.v_StorageStructLevel ssl
                   on ssl.MedService_id = md.MedService_id -- Структурный уровень склада
         left join dbo.v_DrugOstatRegistry dor
                   on dor.Storage_id = ssl.Storage_id and dor.Drug_id = dr.Drug_id

-- end from
  WHERE
        -- where
        vd.VaccinationData_PlanDate <= '2022-04-16' and rg.LpuRegion_id = 890101000000058 and (lpu.Lpu_id = 13101853) and (lpu.Lpu_id = '13101853') and vd.VaccinationData_PlanDate <= '2022-04-16' and vd.VaccinationData_PlanDate >= '2022-03-16' and v.Vaccination_id is not null
        -- end where
        




