====== pears.NetClientDatedPreviousEmployeesFiltered ====== Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace. ===== Original SQL ===== create procedure "pears"."NetClientDatedPreviousEmployeesFiltered"( in "pWebUserID" char(20),in "pFromDate" char(20),in "pToDate" char(20) ) result( "Name" char(100),"PersonID" char(20),"KeyName" char(100),"FirstDate" date,"LatestDate" date ) begin declare "pstart" date; declare "pend" date; declare local temporary table "Cos"( "CompanyID" char(20) null, ) not transactional; declare local temporary table "Pes"( "PersonID" char(20) null, "FirstDate" date null, "LatestDate" date null, ) not transactional;insert into "Cos"( "CompanyID" ) select distinct "companyid" from "employment" key join "iqxnetuserlink" where "iqxnetuserid" = "pWebUserID"; set "pStart" = "isnull"("iqxnetstringtodate"("pFromDate"),"dateadd"("month",-6,current date)); set "pEnd" = "isnull"("iqxnetstringtodate"("pToDate"),"dateadd"("month",1,current date)); -- Get all the People who have worked in the period for those Companies insert into "Pes"( "PersonID" ) select distinct "e"."personid" from "employment" as "e" key join "placement" ,"employment" as "e" join "Cos" on "e"."CompanyID" = "Cos"."CompanyID" where not "e"."personid" = any(select "personid" from "employment" where "companyid" = "e"."companyid" and "noreemploy" = 1) and "e"."startdate" >= "IQXNetCompanyStartDate"("e"."companyid"); -- Add the dates update "pes" set "firstdate" = (select "min"("e"."startdate") from "employment" as "e" join "cos" on "e"."companyid" = "cos"."companyid" where "personid" = "pes"."personid" and "e"."startdate" is not null); update "pes" set "latestdate" = (select "max"("isnull"("e"."leavedate",current date)) from "employment" as "e" join "cos" on "e"."companyid" = "cos"."companyid" where "personid" = "pes"."personid"); -- Get the Peoples details select "person"."name","person"."personid","person"."keyname","pes"."FirstDate","pes"."LatestDate" from "person" join "PES" on "Pes"."PersonID" = "Person"."PersonID" where "pes"."latestdate" between "pStart" and "pEnd" order by "person"."keyname" asc end go COMMENT TO PRESERVE FORMAT ON PROCEDURE "pears"."NetClientDatedPreviousEmployeesFiltered" IS {create procedure pears."NetClientDatedPreviousEmployeesFiltered"( in "pWebUserID" char(20),in "pFromDate" char(20),in "pToDate" char(20) ) result( "Name" char(100),"PersonID" char(20),"KeyName" char(100),"FirstDate" date,"LatestDate" date ) begin declare "pstart" date; declare "pend" date; declare local temporary table "Cos"( "CompanyID" char(20) null, ) not transactional; declare local temporary table "Pes"( "PersonID" char(20) null, "FirstDate" date null, "LatestDate" date null, ) not transactional;insert into "Cos"( "CompanyID" ) select distinct "companyid" from "employment" key join "iqxnetuserlink" where "iqxnetuserid" = "pWebUserID"; set "pStart" = "isnull"("iqxnetstringtodate"("pFromDate"),"dateadd"("month",-6,current date)); set "pEnd" = "isnull"("iqxnetstringtodate"("pToDate"),"dateadd"("month",1,current date)); -- Get all the People who have worked in the period for those Companies insert into "Pes"( "PersonID" ) select distinct "e"."personid" from "employment" as "e" key join "placement" ,"employment" as "e" join "Cos" on "e"."CompanyID" = "Cos"."CompanyID" where not "e"."personid" = any(select "personid" from "employment" where "companyid" = "e"."companyid" and "noreemploy" = 1) and "e"."startdate" >= "IQXNetCompanyStartDate"("e"."companyid"); -- Add the dates update "pes" set "firstdate" = (select "min"("e"."startdate") from "employment" as "e" join "cos" on "e"."companyid" = "cos"."companyid" where "personid" = "pes"."personid" and "e"."startdate" is not null); update "pes" set "latestdate" = (select "max"("isnull"("e"."leavedate",current date)) from "employment" as "e" join "cos" on "e"."companyid" = "cos"."companyid" where "personid" = "pes"."personid"); -- Get the Peoples details select "person"."name","person"."personid","person"."keyname","pes"."FirstDate","pes"."LatestDate" from "person" join "PES" on "Pes"."PersonID" = "Person"."PersonID" where "pes"."latestdate" between "pStart" and "pEnd" order by "person"."keyname" asc end }