
SELECT EV.EvnVaccination_id as "EvnVaccination_id",
   	   EV.EvnVaccination_isManual as "EvnVaccination_isManual",
       to_char( E.Evn_setDT, 'DD.MM.YYYY') as "Evn_updDT",
       V.VaccinationType_id as "VaccinationType_id",
       V.Vaccination_Name as "Vaccination_Name"
FROM dbo.v_EvnVaccination EV
         INNER JOIN vc.VaccinationData VD
                    ON EV.EvnVaccination_id = VD.EvnVaccination_id
         LEFT OUTER JOIN vc.Vaccination V
                         ON V.Vaccination_id = VD.Vaccination_id
         LEFT OUTER JOIN dbo.EvnStatus ES
                         ON ES.EvnStatus_id = EV.EvnStatus_id
                             AND ES.EvnClass_id = 212
         LEFT JOIN dbo.Evn E ON E.Evn_id = EV.EvnVaccination_id
WHERE COALESCE(EV.EvnStatus_id, 0) = 40
   and EV.Person_id = '1489949'
   and V.VaccinationType_id = 123
   and (DATEDIFF('day', E.Evn_setDT, GETDATE()) between 90 and 180) 
   and EV.EvnVaccination_ScarSize is null
