====== pears.PersonKeyWordsUpdate ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create procedure "pears"."PersonKeyWordsUpdate"(
/* Application Maintained Function / Procedure - DO NOT EDIT*/
in @ResetAll tinyint default 0 )
begin
if @ResetAll = 0 then
update "PersonKeyWords"
set "StandardKeyWords" = (select "string"("p"."salutation",' ',"p"."Surname",' ',"p"."ForeNames",' ',"p"."AppNumber",' ',"p"."Addr1",' ',"p"."Addr2",' ',"p"."Addr3",' ',"p"."Town",' ',"p"."County",' ',"p"."PostCode",' ',"PayrollNumber",' ',"NI",' ',
(select "list"("n"."number",' ') from "Phone" as "n" where "n"."Who" = 'P' and "n"."number" like '% %' and "n"."WhoID" = "p"."PersonID"),' ',
(select "list"("replace"("n"."number",' ',''),' ') from "Phone" as "n" where "n"."Who" = 'P' and "n"."WhoID" = "p"."PersonID")) from "Person" as "p" where "p"."PersonID" = "PersonKeyWords"."PersonID"),
"TagKeyWords" = "nullif"("PersonKeyWordsQuestion"("PersonKeyWords"."PersonID"),''),
"CustomKeyWords" = "nullif"("PersonKeyWordsCustom"("PersonKeyWords"."PersonID"),''),
"RefreshRequired" = 0,
"CustomRefreshRequired" = 0,
"TagRefreshRequired" = 0 // this is included abouve, so does not need to be done again
where "RefreshRequired" = 1;
// carry out any tag only updates required
update "PersonKeyWords"
set "TagKeyWords" = "PersonKeyWordsQuestion"("PersonKeyWords"."PersonID"),
"TagRefreshRequired" = 0
where "TagRefreshRequired" = 1;
update "PersonKeyWords"
set "CustomKeyWords" = "nullif"("PersonKeyWordsCustom"("PersonKeyWords"."PersonID"),''),
"CustomRefreshRequired" = 0
where "CustomRefreshRequired" = 1
elseif @ResetAll = 1 then
update "PersonKeyWords" set "RefreshRequired" = 1 // All records will be refreshed on the next triggering of the procedure (normally by the event)
end if
end
go
COMMENT TO PRESERVE FORMAT ON PROCEDURE "pears"."PersonKeyWordsUpdate" IS
{create procedure PersonKeyWordsUpdate
/* Application Maintained Function / Procedure - DO NOT EDIT*/
(IN @ResetAll tinyint default 0)
begin
if @ResetAll = 0 then
update PersonKeyWords
set
StandardKeyWords = (select string(p.salutation, ' ' ,p.Surname,' ',p.ForeNames,' ',p.AppNumber,' ',p.Addr1,' ',p.Addr2,' ',p.Addr3,' ',p.Town,' ',p.County,' ',p.PostCode, ' ', PayrollNumber, ' ', NI, ' ',
(select list(n.number,' ') from Phone n where n.Who = 'P' and n.number like '% %' and n.WhoID = p.PersonID), ' ',
(select list(replace(n.number,' ',''),' ') from Phone n where n.Who = 'P' and n.WhoID = p.PersonID)) from Person p where p.PersonID = PersonKeyWords.PersonID),
TagKeyWords = nullif(PersonKeyWordsQuestion(PersonKeyWords.PersonID),''),
CustomKeyWords = nullif(PersonKeyWordsCustom(PersonKeyWords.PersonID),''),
RefreshRequired = 0,
CustomRefreshRequired = 0,
TagRefreshRequired = 0 // this is included abouve, so does not need to be done again
where RefreshRequired = 1;
// carry out any tag only updates required
update PersonKeyWords
set
TagKeyWords = PersonKeyWordsQuestion(PersonKeyWords.PersonID),
TagRefreshRequired = 0
where TagRefreshRequired = 1;
update PersonKeyWords
set
CustomKeyWords = nullif(PersonKeyWordsCustom(PersonKeyWords.PersonID),''),
CustomRefreshRequired = 0
where CustomRefreshRequired = 1;
elseif @ResetAll = 1
then update PersonKeyWords set RefreshRequired = 1; // All records will be refreshed on the next triggering of the procedure (normally by the event)
end if;
end
}