BEGIN TRANSACTION;

BEGIN TRY

DELETE 
from AS_CAPITALES 
where EmpID =476
and COT_Id in (
select COT_Id 
FROM AS_COTIZACIONES ac 
where 
EmpID =476
and OPT_ID in (171801,171747,171617,171075,169916,169890,169893,165209,164277,163765,163336,163330,163311,163295)
and PRO_ID not in ( select DISTINCT TipSegID from TipSeguros ts where EmpID=476)
);


DELETE
FROM AS_COTIZACIONES 
where 
EmpID =476
and OPT_ID in (171801,171747,171617,171075,169916,169890,169893,165209,164277,163765,163336,163330,163311,163295)
and PRO_ID not in ( select DISTINCT TipSegID from TipSeguros ts where EmpID=476);


    COMMIT TRANSACTION;
END TRY
BEGIN CATCH
    ROLLBACK TRANSACTION;
    PRINT 'Error: ' + ERROR_MESSAGE();
END CATCH;