====== pears.NetQuestionAudit ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create procedure "pears"."NetQuestionAudit"(
in "pTagLocation" char(3),in "pTagID" char(3),in "pID" char(20),in "pOldValue" long varchar )
begin
declare "iAudit" smallint;
declare "NewValue" long varchar;
declare "stagdescrip" char(100);
declare "sname" char(100);
declare "stype" char(12);
select "description","auditflag" into "stagdescrip","iAudit" from "tag" where "taglocation" = "pTagLocation" and "tagid" = "pTagID";
if "trim"("isnull"("iAudit",0)) = 0 then
return
end if;
set "NewValue" = "getquestanswer"("pTagLocation","pTagID","pID");
case
when "pTagLocation" = 'C' then
set "stype" = 'COMPANY';
select "name" into "sname" from "company" where "companyid" = "pID"
when "pTagLocation" = 'P' or "pTagLocation" like 'A%' then
set "stype" = 'PERSON';
select "name" into "sname" from "person" where "personid" = "pID"
when "pTagLocation" = 'E' then
set "stype" = 'COMPANY';
select "company"."companyid","string"("person"."name",', ',"company"."name") into "pID","sname" from "employment" key join("person","company") where "employment"."employmentid" = "pID"
when "pTagLocation" like 'V%' then
set "stype" = 'VACANCY';
select "string"("Company"."Name",' - ',"vacancy"."position",'(',"vacancy"."RefCode",')') into "sname" from "vacancy" key join "employment" key join "Company" where "vacancy"."vacancyid" = "pID"
when "pTagLocation" like 'L%' then
set "stype" = 'PLACEMENT';
select "string"("Company"."Name",' - ',"employment"."position") into "sname" from "placement" key join "employment" key join "Company" where "placement"."placementid" = "pID"
when "pTagLocation" like 'S%' then
set "stype" = 'SHIFTPLAN'
when "pTagLocation" like 'T%' then
set "stype" = 'TIMESHEET';
select
"isnull"(
(select first if "c"."Name" is not null then
"string"("t"."SerialNumber",': ',"p"."Name",' as ',"v"."Position",' at ',"c"."Name")
else "string"("t"."SerialNumber",': ',"p"."Name",' - Internal ')
endif from "TempTimeSheet" as "t" key join "Person" as "p","TempTimeSheet" as "t" key left outer join("Placement" key join "Vacancy" as "v" key join "Employment" key join "Company" as "c") where "t"."TempTimeSheetID" = "pID"),
(select first "string"("t"."SerialNumber",'(P): ',"p"."Name",' as ',"v"."Position",' at ',"c"."Name") from "TempProvTimeSheet" as "t" key left outer join "Person" as "p","TempProvTimeSheet" as "t"
key left outer join("Vacancy" as "v" key join "Employment" key join "Company" as "c") where "t"."TempProvTimeSheetID" = "pID"))
into "sname"
when "pTagLocation" like 'N%' then
set "stype" = 'CEVENT'
when "pTagLocation" = 'U' then
set "stype" = 'USER'
when "pTagLocation" like 'R%' then
set "stype" = 'REFER'
when "pTagLocation" = 'I' then
set "stype" = 'PURCH'
when "pTagLocation" = 'X' then
set "stype" = 'AGENCY'
when "pTagLocation" like 'J%' then
set "stype" = 'COLLECT'
else
set "stype" = "string"('TAG ',"pTagLocation")
end case;
if "length"("pTagLocation") > 1 then
set "stagdescrip" = "string"((select "name"+' ' from "department" where "departmentid" = "substring"("pTagLocation",2)),"stagdescrip")
end if;
if "isnull"("sname",'') <> '' then
set "sname" = ' - '+"sname"
end if;
set "sname" = "string"("stagdescrip",' Updated',"sname");
call "AuditLog"("stype","pID","sname","isnull"("pOldValue",''),"isnull"("NewValue",''))
end
go
COMMENT TO PRESERVE FORMAT ON PROCEDURE "pears"."NetQuestionAudit" IS
{create PROCEDURE pears."NetQuestionAudit"
(in pTagLocation char(3), in pTagID char(3), in pID char(20), in pOldValue long varchar )
begin
declare iAudit smallint;
declare NewValue long varchar;
declare stagdescrip char(100);
declare sname char(100);
declare stype char(12);
select description,auditflag into stagdescrip,iAudit from tag where taglocation=pTagLocation and tagid=pTagID;
if trim(isnull(iAudit,0))=0 then
return
end if;
set NewValue=getquestanswer(pTagLocation,pTagID,pID);
CASE
when pTagLocation='C' then
set stype = 'COMPANY';
select name into sname from company where companyid = pID;
when pTagLocation = 'P' or pTagLocation like 'A%' then
set stype = 'PERSON';
select name into sname from person where personid = pID;
when pTagLocation = 'E' then
set stype = 'COMPANY';
select company.companyid,string(person.name,', ',company.name) into pID,sname from employment key join(person,company) where employment.employmentid = pID;
when pTagLocation like 'V%' then
set stype = 'VACANCY';
select string(Company.Name,' - ',vacancy.position,'(',vacancy.RefCode,')') into sname from vacancy key join employment key join Company where vacancy.vacancyid = pID;
when pTagLocation like 'L%' then
set stype = 'PLACEMENT';
select string(Company.Name,' - ',employment.position) into sname from placement key join employment key join Company where placement.placementid = pID;
when pTagLocation like 'S%' then
set stype = 'SHIFTPLAN';
when pTagLocation like 'T%' then
set stype = 'TIMESHEET';
select
isnull(
(select first if c.Name is not null then
string(t.SerialNumber,': ',p.Name,' as ',v.Position,' at ',c.Name)
else string(t.SerialNumber,': ',p.Name,' - Internal ')
endif from TempTimeSheet as t key join Person as p,TempTimeSheet as t key left outer join(Placement key join Vacancy as v key join Employment key join Company as c) where t.TempTimeSheetID = pID),
(select first string(t.SerialNumber,'(P): ',p.Name,' as ',v.Position,' at ',c.Name) from TempProvTimeSheet as t key left outer join Person as p,TempProvTimeSheet as t
key left outer join(Vacancy as v key join Employment key join Company as c) where t.TempProvTimeSheetID = pID))
into sname;
when pTagLocation like 'N%' then
set stype = 'CEVENT';
when pTagLocation = 'U' then
set stype = 'USER';
when pTagLocation like 'R%' then
set stype = 'REFER';
when pTagLocation = 'I' then
set stype = 'PURCH';
when pTagLocation = 'X' then
set stype = 'AGENCY';
when pTagLocation like 'J%' then
set stype = 'COLLECT';
else
set stype = string('TAG ',pTagLocation);
END CASE;
if length(pTagLocation) > 1 then
set stagdescrip = string((select name + ' ' from department where departmentid = substring(pTagLocation,2)), stagdescrip)
end if;
if isnull(sname,'')<>'' then
set sname=' - '+sname;
end if;
set sname = string(stagdescrip,' Updated',sname);
call AuditLog(stype,pID,sname,isnull(pOldValue,''),isnull(NewValue,''))
end
}