====== pears.AWRLinkedPlacements ====== Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace. ===== Original SQL ===== create procedure "pears"."AWRLinkedPlacements"( in "JobMid" char(20),in "placeid" char(20) ) result( "Jobmasterid" char(20),"Linkedflag" char(1) ) begin -- return a list of already linked AWR records in the correct order and potential linked ones declare @lecode char(50); declare @linkcode char(50); declare @personid char(20); declare @companyid char(20); select "LECode","AWRLinkCode","employment"."personid","company"."companyid" into @lecode,@linkcode,@personid,@companyid from "AWRCompany" key join "company" key join "employment" key join "placement" key join "AWRjobmaster" where "AWRJobmasterid" = "jobmid"; if @LECode is null then select "AWRJobmasterid",(if "AWRLinkCode" is not null and "AWRLinkCode" = @linkcode then 'Y' else 'N' endif) from "AWRJobmaster" key join "placement" key join "employment" key join "company" key join "AWRcompany" where "company"."companyid" = @companyid and "AWRJobMasterID" <> "JobMid" and "employment"."personid" = @personid else select "AWRJobmasterid",(if "AWRLinkCode" is not null and "AWRLinkCode" = @linkcode then 'Y' else 'N' endif) from "AWRJobmaster" key join "placement" key join "employment" key join "company" key join "AWRcompany" where "LECode" = @LECode and "AWRJobMasterID" <> "JobMid" and "employment"."personid" = @personid end if end