====== pears.psHealthInsertUpdateVacancy ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create procedure "pears"."psHealthInsertUpdateVacancy"(
in @VacancyID char(20) )
begin
declare "recipid" char(20);
select "recipientid" into "recipid" from "vacancy" where "vacancyid" = @VacancyID;
if("recipid" is null) or exists(select * from "psHealthVacancy" where "vacancyid" = @Vacancyid) then
return
end if; -- no resending
if "psHealthCanSendPerson"("recipid",'R') = 1 then
call "psHealthInsertUpdatePerson"("recipid",'R');
insert into "psHealthVacancy"( "psHealthVacancyID","startDateTime","Status","tenantCaseId","tenantCustomerId","transferbatch","vacancyid","tenantBranchID" )
select "uniquekey"('x'),"startdate",'Referred',
"refcode",(select "appnumber" from "person" where "personid" = "recipientid"),0,"vacancyid","psHealthBranch"(null,null,"recipid",'R') from "vacancy" where "vacancyid" = @vacancyid
end if
end