select nomesp,(select count(codevepar) from gevmdeventosparticipantes,gevtparticipantes where (gevmdeventosparticipantes.codpar=gevtparticipantes.codpar) and (codeve='@1') and (codesp=gevtespecialidades.codesp) and (  (((gevmdeventosparticipantes.tippre='S') or (gevmdeventosparticipantes.tippre='P')) and (stapatinc='S')) or ((tippre='N')) )  ) as cantidad from gevtespecialidades where (codesp in (select codesp from gevtparticipantes,gevmdeventosparticipantes where (codeve='@1') and (gevtparticipantes.codpar=gevmdeventosparticipantes.codpar)  and (  (((gevmdeventosparticipantes.tippre='S') or (gevmdeventosparticipantes.tippre='P')) and (stapatinc='S')) or ((tippre='N')) )  ))