pears.CreateETimesheetRates

Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.

Original SQL

CREATE PROCEDURE "pears"."CreateETimesheetRates"( 
  /* Application Maintained Function / Procedure - DO NOT EDIT*/
  IN "ptsid" CHAR(20),IN "ppersid" CHAR(20),IN "pvacid" CHAR(20),IN "pplacid" CHAR(20),IN "pweekstart" DATE,IN "pweekend" DATE,
  IN "pjobtypeid" CHAR(20) DEFAULT NULL,IN "punderlyingscheme" SMALLINT DEFAULT 0 ) 
BEGIN
  DECLARE "pbandid" CHAR(20);
  DECLARE "ppayrate" DOUBLE;
  DECLARE "pchgrate" DOUBLE;
  DECLARE "pgrade" CHAR(4);
  DECLARE "pfilter1" CHAR(4);
  DECLARE "pfilter2" CHAR(4);
  DECLARE "pfilter3" CHAR(4);
  DECLARE "plineno" SMALLINT;
  DECLARE "pweekno" INTEGER;
  SET "pweekno" = "weekcontaining"("pweekend");
  SET "plineno" = 0;
  IF "trim"("isnull"("pjobtypeid",'')) = '' THEN
    SELECT "tempjobtypeid" INTO "pjobtypeid" FROM "vacancy" WHERE "vacancyid" = "pvacid"
  END IF;
  IF "punderlyingscheme" IS NULL THEN
    SET "punderlyingscheme" = 0
  END IF;
  -- SQL taken from TimeSheetEntry.qRates
  FOR "PRATEFOR" AS "PRATECUR" no scroll cursor FOR
    SELECT "temppayband"."sortorder","temppayband"."TempPayBandID","temppayband"."description","isnull"("tempjobrate"."Grade",'') AS "Grade",
      "tempjobrate"."filter1","tempjobrate"."filter2","tempjobrate"."filter3",
      "vacancytemprate"("pvacid","temppayband"."temppayBandID","tempjobrate"."grade","tempjobrate"."filter1","tempjobrate"."filter2","tempjobrate"."filter3","tempjobrate"."Startdate","tempjobrate"."Enddate") AS "VacRateID",
      "mastertemprate"("pjobtypeid","temppayband"."temppayBandID","tempjobrate"."grade","tempjobrate"."filter1","tempjobrate"."filter2","tempjobrate"."filter3","tempjobrate"."Startdate","tempjobrate"."Enddate") AS "MasterID",
      "tempjobrate"."Startdate" AS "StartDate",
      "tempjobrate"."Enddate" AS "EndDate",
      "tempjobrate"."TempJobRateID",
      (SELECT FIRST "discount" FROM "tempjobtype" WHERE "tempjobtypeid" = "pjobtypeid") AS "masterdiscount",
      "tempjobrate"."PayRate" AS "SavedPayRate",
      (SELECT FIRST "payrate" FROM "tempjobratemaster" WHERE "tempjobratemasterid" = "masterid") AS "MasterPayRate",
      "isnull"((SELECT FIRST "payrate" FROM "tempjobrate" WHERE "tempjobrateid" = "vacrateid"),"MasterPayRate") AS "OrigPayRate",
      "ModifiedTempRate"('P',"pvacid","ppersid","pplacid","temppayband"."temppaybandid","OrigPayRate") AS "ModifiedPayRate",
      "isnull"("SavedPayRate","ModifiedPayRate") AS "PayRate",
      "tempjobrate"."ChargeRate" AS "SavedChargeRate",
      (SELECT FIRST "chargerate" FROM "tempjobratemaster" WHERE "tempjobratemasterid" = "masterid") AS "MasterChargeRate",
      "isnull"((SELECT FIRST "chargerate" FROM "tempjobrate" WHERE "tempjobrateid" = "vacrateid"),"MasterChargeRate") AS "OrigChargeRate",
      "round"("origchargerate"-("isnull"((SELECT FIRST "discount" FROM "vacancy" WHERE "vacancyid" = "pvacid"),0)*"origchargerate"/100),2) AS "DiscountedCharge",
      "ModifiedTempRate"('C',"pvacid","ppersid","pplacid","temppayband"."temppaybandid","DiscountedCharge") AS "ModifiedChargeRate",
      "isnull"("SavedChargeRate","ModifiedChargeRate") AS "ChargeRate",
      "round"("masterchargerate"-("isnull"("masterdiscount",0)*"masterchargerate"/100),2) AS "MasterDiscountedCharge",
      "tempjobrate"."placementid","temppayband"."payrollflag"
      FROM "tempjobrate" KEY JOIN "temppayband"
      WHERE "tempjobrate"."placementid" = "pplacid" AND "punderlyingscheme" = 0
      AND("startdate" IS NULL OR "startdate" <= "pweekend") AND("enddate" IS NULL OR "enddate" >= "pweekstart")
      AND("tempjobrate"."grade" IS NULL OR "tempjobrate"."grade" LIKE "isnull"("entitygrade"("pvacid","ppersid","pplacid",NULL),'%'))
      AND("tempjobrate"."filter1" IS NULL OR "tempjobrate"."filter1" LIKE "isnull"("entityratefilter"(1,"pweekno","pvacid","ppersid","pplacid",NULL),'%'))
      AND("tempjobrate"."filter2" IS NULL OR "tempjobrate"."filter2" LIKE "isnull"("entityratefilter"(2,"pweekno","pvacid","ppersid","pplacid",NULL),'%'))
      AND("tempjobrate"."filter3" IS NULL OR "tempjobrate"."filter3" LIKE "isnull"("entityratefilter"(3,"pweekno","pvacid","ppersid","pplacid",NULL),'%')) UNION ALL
    SELECT "temppayband"."sortorder","temppayband"."TempPayBandID","temppayband"."description","isnull"("tempjobrate"."Grade",'') AS "Grade",
      "tempjobrate"."filter1","tempjobrate"."filter2","tempjobrate"."filter3",
      "tempjobrate"."TempJobRateID" AS "VacRateID",
      "mastertemprate"("pjobtypeid","temppayband"."temppayBandID","tempjobrate"."grade","tempjobrate"."filter1","tempjobrate"."filter2","tempjobrate"."filter3","tempjobrate"."Startdate","tempjobrate"."Enddate") AS "MasterID",
      "tempjobrate"."Startdate" AS "StartDate",
      "tempjobrate"."Enddate" AS "EndDate",
      CAST(NULL AS CHAR(20)) AS "TempJobRateID",
      (SELECT FIRST "discount" FROM "tempjobtype" WHERE "tempjobtypeid" = "pjobtypeid") AS "masterdiscount",
      CAST(NULL AS DOUBLE) AS "SavedPayRate",
      (SELECT FIRST "payrate" FROM "tempjobratemaster" WHERE "tempjobratemasterid" = "masterid") AS "MasterPayRate",
      "isnull"("tempjobrate"."payrate","MasterPayRate") AS "OrigPayRate",
      "ModifiedTempRate"('P',"pvacid","ppersid","pplacid","temppayband"."temppaybandid","OrigPayRate") AS "ModifiedPayRate",
      "ModifiedPayRate" AS "PayRate",
      CAST(NULL AS DOUBLE) AS "SavedChargeRate",
      (SELECT FIRST "chargerate" FROM "tempjobratemaster" WHERE "tempjobratemasterid" = "masterid") AS "MasterChargeRate",
      "isnull"("tempjobrate"."chargerate","MasterChargeRate") AS "OrigChargeRate",
      "round"("origchargerate"-("isnull"((SELECT FIRST "discount" FROM "vacancy" WHERE "vacancyid" = "pvacid"),0)*"origchargerate"/100),2) AS "DiscountedCharge",
      "ModifiedTempRate"('C',"pvacid","ppersid","pplacid","temppayband"."temppaybandid","DiscountedCharge") AS "ModifiedChargeRate",
      "ModifiedChargeRate" AS "ChargeRate",
      "round"("masterchargerate"-("isnull"("masterdiscount",0)*"masterchargerate"/100),2) AS "MasterDiscountedCharge",
      CAST("pplacid" AS CHAR(20)) AS "placementid","temppayband"."payrollflag"
      FROM "tempjobrate" KEY JOIN "temppayband"
      WHERE "tempjobrate"."vacancyid" = "pvacid" AND "punderlyingscheme" = 0
      AND "OverrideTempRate"(NULL,"pplacid","temppayband"."temppaybandid","tempjobrate"."Grade","tempjobrate"."filter1","tempjobrate"."filter2","tempjobrate"."filter3","tempjobrate"."Startdate","tempjobrate"."Enddate") IS NULL
      AND("startdate" IS NULL OR "startdate" <= "pweekend") AND("enddate" IS NULL OR "enddate" >= "pweekstart")
      AND("tempjobrate"."grade" IS NULL OR "tempjobrate"."grade" LIKE "isnull"("entitygrade"("pvacid","ppersid","pplacid",NULL),'%'))
      AND("tempjobrate"."filter1" IS NULL OR "tempjobrate"."filter1" LIKE "isnull"("entityratefilter"(1,"pweekno","pvacid","ppersid","pplacid",NULL),'%'))
      AND("tempjobrate"."filter2" IS NULL OR "tempjobrate"."filter2" LIKE "isnull"("entityratefilter"(2,"pweekno","pvacid","ppersid","pplacid",NULL),'%'))
      AND("tempjobrate"."filter3" IS NULL OR "tempjobrate"."filter3" LIKE "isnull"("entityratefilter"(3,"pweekno","pvacid","ppersid","pplacid",NULL),'%')) UNION ALL
    SELECT "temppayband"."sortorder","temppayband"."TempPayBandID","temppayband"."description","isnull"("tempjobratemaster"."Grade",'') AS "Grade",
      "tempjobratemaster"."filter1","tempjobratemaster"."filter2","tempjobratemaster"."filter3",
      CAST(NULL AS CHAR(20)) AS "VacRateID",
      "tempjobratemaster"."tempjobratemasterid" AS "masterid",
      "tempjobratemaster"."Startdate" AS "StartDate",
      "tempjobratemaster"."Enddate" AS "EndDate",
      CAST(NULL AS CHAR(20)) AS "TempJobRateID",
      "tempjobtype"."discount" AS "masterdiscount",
      CAST(NULL AS DOUBLE) AS "SavedPayRate",
      "tempjobratemaster"."payrate" AS "MasterPayRate",
      "MasterPayRate" AS "OrigPayRate",
      "ModifiedTempRate"('P',"pvacid","ppersid","pplacid","temppayband"."temppaybandid","OrigPayRate") AS "ModifiedPayRate",
      "ModifiedPayRate" AS "PayRate",
      CAST(NULL AS DOUBLE) AS "SavedChargeRate",
      "tempjobratemaster"."chargerate" AS "MasterChargeRate",
      "MasterChargeRate" AS "OrigChargeRate",
      "round"("origchargerate"-("isnull"((SELECT FIRST "Discount" FROM "vacancy" WHERE "vacancyid" = "pvacid"),0)*"origchargerate"/100),2) AS "DiscountedCharge",
      "ModifiedTempRate"('C',"pvacid","ppersid","pplacid","temppayband"."temppaybandid","DiscountedCharge") AS "ModifiedChargeRate",
      "ModifiedChargeRate" AS "ChargeRate",
      "round"("masterchargerate"-("isnull"("masterdiscount",0)*"masterchargerate"/100),2) AS "MasterDiscountedCharge",
      CAST("pplacid" AS CHAR(20)) AS "placementid","temppayband"."payrollflag"
      FROM "tempjobratemaster" KEY JOIN("tempjobtype","temppayband")
      WHERE "tempjobtype"."tempjobtypeid" = "pjobtypeid" AND("punderlyingscheme" = 1
      OR("OverrideTempRate"("pvacid","pplacid","temppayband"."temppaybandid","tempjobratemaster"."Grade","tempjobratemaster"."filter1","tempjobratemaster"."filter2","tempjobratemaster"."filter3","tempjobratemaster"."Startdate","tempjobratemaster"."Enddate") IS NULL
      AND "tempjobtype"."dynamic" = 1))
      AND("startdate" IS NULL OR "startdate" <= "pweekend") AND("enddate" IS NULL OR "enddate" >= "pweekstart")
      AND("tempjobratemaster"."grade" IS NULL OR "tempjobratemaster"."grade" LIKE "isnull"("entitygrade"("pvacid","ppersid","pplacid",NULL),'%'))
      AND("tempjobratemaster"."filter1" IS NULL OR "tempjobratemaster"."filter1" LIKE "isnull"("entityratefilter"(1,"pweekno","pvacid","ppersid","pplacid",NULL),'%'))
      AND("tempjobratemaster"."filter2" IS NULL OR "tempjobratemaster"."filter2" LIKE "isnull"("entityratefilter"(2,"pweekno","pvacid","ppersid","pplacid",NULL),'%'))
      AND("tempjobratemaster"."filter3" IS NULL OR "tempjobratemaster"."filter3" LIKE "isnull"("entityratefilter"(3,"pweekno","pvacid","ppersid","pplacid",NULL),'%'))
      ORDER BY 1 ASC,3 ASC,4 ASC FOR READ ONLY do
    SET "plineno" = "plineno"+1;
    SET "pbandid" = "temppaybandid";
    SET "ppayrate" = "payrate";
    SET "pchgrate" = "chargerate";
    SET "pgrade" = "grade";
    SET "pfilter1" = "filter1";
    SET "pfilter2" = "filter2";
    SET "pfilter3" = "filter3";
    INSERT INTO "tempprovtimesheetline"( "tempprovtimesheetlineid","tempprovtimesheetid","temppaybandid","linenumber","payrate","chargerate","grade","filter1","filter2","filter3" ) VALUES
      ( "uniquekey"("plineno"),"ptsid","pbandid","plineno","ppayrate","pchgrate","pgrade","pfilter1","pfilter2","pfilter3" ) 
  END FOR
END
GO
 
COMMENT TO PRESERVE FORMAT ON PROCEDURE "pears"."CreateETimesheetRates" IS 
{CREATE PROCEDURE CreateETimesheetRates 
 
/* Application Maintained Function / Procedure - DO NOT EDIT*/
 
( 
  IN ptsid CHAR(20),IN ppersid CHAR(20),IN pvacid CHAR(20),IN pplacid CHAR(20),IN pweekstart DATE,IN pweekend DATE,
  IN pjobtypeid CHAR(20) DEFAULT NULL,IN punderlyingscheme SMALLINT DEFAULT 0 ) 
BEGIN
  DECLARE pbandid CHAR(20);
  DECLARE ppayrate DOUBLE;
  DECLARE pchgrate DOUBLE;
  DECLARE pgrade CHAR(4);
  DECLARE pfilter1 CHAR(4);
  DECLARE pfilter2 CHAR(4);
  DECLARE pfilter3 CHAR(4);
  DECLARE plineno SMALLINT;
  DECLARE pweekno INTEGER;
  SET pweekno = weekcontaining(pweekend);
  SET plineno = 0;
  IF TRIM(isnull(pjobtypeid,'')) = '' THEN
    SELECT tempjobtypeid INTO pjobtypeid FROM vacancy WHERE vacancyid = pvacid
  END IF;
  IF punderlyingscheme IS NULL THEN
    SET punderlyingscheme = 0
  END IF;
  -- SQL taken from TimeSheetEntry.qRates
  FOR PRATEFOR AS PRATECUR no scroll cursor FOR
    SELECT temppayband.sortorder,temppayband.TempPayBandID,temppayband.description,isnull(tempjobrate.Grade,'') AS Grade,
      tempjobrate.filter1,tempjobrate.filter2,tempjobrate.filter3,
      vacancytemprate(pvacid,temppayband.temppayBandID,tempjobrate.grade,tempjobrate.filter1,tempjobrate.filter2,tempjobrate.filter3,tempjobrate.Startdate,tempjobrate.Enddate) AS VacRateID,
      mastertemprate(pjobtypeid,temppayband.temppayBandID,tempjobrate.grade,tempjobrate.filter1,tempjobrate.filter2,tempjobrate.filter3,tempjobrate.Startdate,tempjobrate.Enddate) AS MasterID,
      tempjobrate.Startdate AS StartDate,
      tempjobrate.Enddate AS EndDate,
      tempjobrate.TempJobRateID,
      (SELECT FIRST discount FROM tempjobtype WHERE tempjobtypeid = pjobtypeid) AS masterdiscount,
      tempjobrate.PayRate AS SavedPayRate,
      (SELECT FIRST payrate FROM tempjobratemaster WHERE tempjobratemasterid = masterid) AS MasterPayRate,
      isnull((SELECT FIRST payrate FROM tempjobrate WHERE tempjobrateid = vacrateid),MasterPayRate) AS OrigPayRate,
      ModifiedTempRate('P',pvacid,ppersid,pplacid,temppayband.temppaybandid,OrigPayRate) AS ModifiedPayRate,
      isnull(SavedPayRate,ModifiedPayRate) AS PayRate,
      tempjobrate.ChargeRate AS SavedChargeRate,
      (SELECT FIRST chargerate FROM tempjobratemaster WHERE tempjobratemasterid = masterid) AS MasterChargeRate,
      isnull((SELECT FIRST chargerate FROM tempjobrate WHERE tempjobrateid = vacrateid),MasterChargeRate) AS OrigChargeRate,
      round(origchargerate-(isnull((SELECT FIRST discount FROM vacancy WHERE vacancyid = pvacid),0)*origchargerate/100),2) AS DiscountedCharge,
      ModifiedTempRate('C',pvacid,ppersid,pplacid,temppayband.temppaybandid,DiscountedCharge) AS ModifiedChargeRate,
      isnull(SavedChargeRate,ModifiedChargeRate) AS ChargeRate,
      round(masterchargerate-(isnull(masterdiscount,0)*masterchargerate/100),2) AS MasterDiscountedCharge,
      tempjobrate.placementid,temppayband.payrollflag
      FROM tempjobrate KEY JOIN temppayband
      WHERE tempjobrate.placementid = pplacid AND punderlyingscheme = 0
      AND(startdate IS NULL OR startdate <= pweekend) AND(enddate IS NULL OR enddate >= pweekstart)
      AND(tempjobrate.grade IS NULL OR tempjobrate.grade LIKE isnull(entitygrade(pvacid,ppersid,pplacid,NULL),'%'))
      AND(tempjobrate.filter1 IS NULL OR tempjobrate.filter1 LIKE isnull(entityratefilter(1,pweekno,pvacid,ppersid,pplacid,NULL),'%'))
      AND(tempjobrate.filter2 IS NULL OR tempjobrate.filter2 LIKE isnull(entityratefilter(2,pweekno,pvacid,ppersid,pplacid,NULL),'%'))
      AND(tempjobrate.filter3 IS NULL OR tempjobrate.filter3 LIKE isnull(entityratefilter(3,pweekno,pvacid,ppersid,pplacid,NULL),'%')) UNION ALL
    SELECT temppayband.sortorder,temppayband.TempPayBandID,temppayband.description,isnull(tempjobrate.Grade,'') AS Grade,
      tempjobrate.filter1,tempjobrate.filter2,tempjobrate.filter3,
      tempjobrate.TempJobRateID AS VacRateID,
      mastertemprate(pjobtypeid,temppayband.temppayBandID,tempjobrate.grade,tempjobrate.filter1,tempjobrate.filter2,tempjobrate.filter3,tempjobrate.Startdate,tempjobrate.Enddate) AS MasterID,
      tempjobrate.Startdate AS StartDate,
      tempjobrate.Enddate AS EndDate,
      CAST(NULL AS CHAR(20)) AS TempJobRateID,
      (SELECT FIRST discount FROM tempjobtype WHERE tempjobtypeid = pjobtypeid) AS masterdiscount,
      CAST(NULL AS DOUBLE) AS SavedPayRate,
      (SELECT FIRST payrate FROM tempjobratemaster WHERE tempjobratemasterid = masterid) AS MasterPayRate,
      isnull(tempjobrate.payrate,MasterPayRate) AS OrigPayRate,
      ModifiedTempRate('P',pvacid,ppersid,pplacid,temppayband.temppaybandid,OrigPayRate) AS ModifiedPayRate,
      ModifiedPayRate AS PayRate,
      CAST(NULL AS DOUBLE) AS SavedChargeRate,
      (SELECT FIRST chargerate FROM tempjobratemaster WHERE tempjobratemasterid = masterid) AS MasterChargeRate,
      isnull(tempjobrate.chargerate,MasterChargeRate) AS OrigChargeRate,
      round(origchargerate-(isnull((SELECT FIRST discount FROM vacancy WHERE vacancyid = pvacid),0)*origchargerate/100),2) AS DiscountedCharge,
      ModifiedTempRate('C',pvacid,ppersid,pplacid,temppayband.temppaybandid,DiscountedCharge) AS ModifiedChargeRate,
      ModifiedChargeRate AS ChargeRate,
      round(masterchargerate-(isnull(masterdiscount,0)*masterchargerate/100),2) AS MasterDiscountedCharge,
      CAST(pplacid AS CHAR(20)) AS placementid,temppayband.payrollflag
      FROM tempjobrate KEY JOIN temppayband
      WHERE tempjobrate.vacancyid = pvacid AND punderlyingscheme = 0
      AND OverrideTempRate(NULL,pplacid,temppayband.temppaybandid,tempjobrate.Grade,tempjobrate.filter1,tempjobrate.filter2,tempjobrate.filter3,tempjobrate.Startdate,tempjobrate.Enddate) IS NULL
      AND(startdate IS NULL OR startdate <= pweekend) AND(enddate IS NULL OR enddate >= pweekstart)
      AND(tempjobrate.grade IS NULL OR tempjobrate.grade LIKE isnull(entitygrade(pvacid,ppersid,pplacid,NULL),'%'))
      AND(tempjobrate.filter1 IS NULL OR tempjobrate.filter1 LIKE isnull(entityratefilter(1,pweekno,pvacid,ppersid,pplacid,NULL),'%'))
      AND(tempjobrate.filter2 IS NULL OR tempjobrate.filter2 LIKE isnull(entityratefilter(2,pweekno,pvacid,ppersid,pplacid,NULL),'%'))
      AND(tempjobrate.filter3 IS NULL OR tempjobrate.filter3 LIKE isnull(entityratefilter(3,pweekno,pvacid,ppersid,pplacid,NULL),'%')) UNION ALL
    SELECT temppayband.sortorder,temppayband.TempPayBandID,temppayband.description,isnull(tempjobratemaster.Grade,'') AS Grade,
      tempjobratemaster.filter1,tempjobratemaster.filter2,tempjobratemaster.filter3,
      CAST(NULL AS CHAR(20)) AS VacRateID,
      tempjobratemaster.tempjobratemasterid AS masterid,
      tempjobratemaster.Startdate AS StartDate,
      tempjobratemaster.Enddate AS EndDate,
      CAST(NULL AS CHAR(20)) AS TempJobRateID,
      tempjobtype.discount AS masterdiscount,
      CAST(NULL AS DOUBLE) AS SavedPayRate,
      tempjobratemaster.payrate AS MasterPayRate,
      MasterPayRate AS OrigPayRate,
      ModifiedTempRate('P',pvacid,ppersid,pplacid,temppayband.temppaybandid,OrigPayRate) AS ModifiedPayRate,
      ModifiedPayRate AS PayRate,
      CAST(NULL AS DOUBLE) AS SavedChargeRate,
      tempjobratemaster.chargerate AS MasterChargeRate,
      MasterChargeRate AS OrigChargeRate,
      round(origchargerate-(isnull((SELECT FIRST Discount FROM vacancy WHERE vacancyid = pvacid),0)*origchargerate/100),2) AS DiscountedCharge,
      ModifiedTempRate('C',pvacid,ppersid,pplacid,temppayband.temppaybandid,DiscountedCharge) AS ModifiedChargeRate,
      ModifiedChargeRate AS ChargeRate,
      round(masterchargerate-(isnull(masterdiscount,0)*masterchargerate/100),2) AS MasterDiscountedCharge,
      CAST(pplacid AS CHAR(20)) AS placementid,temppayband.payrollflag
      FROM tempjobratemaster KEY JOIN(tempjobtype,temppayband)
      WHERE tempjobtype.tempjobtypeid = pjobtypeid AND(punderlyingscheme = 1
      OR(OverrideTempRate(pvacid,pplacid,temppayband.temppaybandid,tempjobratemaster.Grade,tempjobratemaster.filter1,tempjobratemaster.filter2,tempjobratemaster.filter3,tempjobratemaster.Startdate,tempjobratemaster.Enddate) IS NULL
      AND tempjobtype."dynamic" = 1))
      AND(startdate IS NULL OR startdate <= pweekend) AND(enddate IS NULL OR enddate >= pweekstart)
      AND(tempjobratemaster.grade IS NULL OR tempjobratemaster.grade LIKE isnull(entitygrade(pvacid,ppersid,pplacid,NULL),'%'))
      AND(tempjobratemaster.filter1 IS NULL OR tempjobratemaster.filter1 LIKE isnull(entityratefilter(1,pweekno,pvacid,ppersid,pplacid,NULL),'%'))
      AND(tempjobratemaster.filter2 IS NULL OR tempjobratemaster.filter2 LIKE isnull(entityratefilter(2,pweekno,pvacid,ppersid,pplacid,NULL),'%'))
      AND(tempjobratemaster.filter3 IS NULL OR tempjobratemaster.filter3 LIKE isnull(entityratefilter(3,pweekno,pvacid,ppersid,pplacid,NULL),'%'))
      ORDER BY 1 ASC,3 ASC,4 ASC FOR READ ONLY do
    SET plineno = plineno+1;
    SET pbandid = temppaybandid;
    SET ppayrate = payrate;
    SET pchgrate = chargerate;
    SET pgrade = grade;
    SET pfilter1 = filter1;
    SET pfilter2 = filter2;
    SET pfilter3 = filter3;
    INSERT INTO tempprovtimesheetline( tempprovtimesheetlineid,tempprovtimesheetid,temppaybandid,linenumber,payrate,chargerate,grade,filter1,filter2,filter3 ) 
      VALUES( uniquekey(plineno),ptsid,pbandid,plineno,ppayrate,pchgrate,pgrade,pfilter1,pfilter2,pfilter3 ) 
  END FOR
END
}