Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread get a value out of a script?
Wed, Jul 25 2018 2:21 AMPermanent Link

Ian Branch

Avatar

Hi Team,
   Given the following script:
{sql}
SCRIPT (IN EndDate Date, OUT RecCount Integer)
BEGIN

  EXECUTE IMMEDIATE 'insert into ajobtickets
  select * from jobtickets
  where (jobstatus = ''CL'' or jobstatus = ''CA'') and Created < ?' using EndDate;

  execute immediate 'delete from JobTickets
  where (jobstatus = ''CL'' or jobstatus = ''CA'') and Created < ?' using EndDate;

  execute immediate 'INSERT INTO ALineItems
  SELECT * from LineItems
  WHERE LineItems.JobNo IN (SELECT JobNo FROM AJobTickets)';

  execute immediate 'DELETE FROM LineItems
  WHERE JobNo IN (SELECT JobNo from ALineItems)';

  execute immediate 'INSERT INTO ATechData
  SELECT * from TechData
  WHERE TechData.JobNo IN (SELECT JobNo FROM AJobTickets)';

  execute immediate 'DELETE FROM TechData
  WHERE JobNo IN (SELECT JobNo from ALineItems)';

END
{sql}

   How do I populate RecCount with the number of records processed by the First or Second EXECUTE please?

Regards & TIA,
Ian
Wed, Jul 25 2018 2:52 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Ian


I think you're looking for the ROWSAFFECTED function but you may have to rewrite a little to use EXECUTE rather than EXECUTE IMMEDIATE. There's a good example in the OLH in EDBManager.

Roy Lambert
Wed, Jul 25 2018 4:09 AMPermanent Link

Ian Branch

Avatar

Hi Roy,
   Thanks for the pointer.  Ended up with this..
{sql}
SCRIPT (IN EndDate Date, OUT RecCount Integer)
BEGIN
  DECLARE sEndDate VARCHAR(10) DEFAULT cast(EndDate as VARCHAR);
  DECLARE InsertStmt Statement;

  PREPARE InsertStmt from 'insert into ajobtickets
  select * from jobtickets
  where (jobstatus = ''CL'' or jobstatus = ''CA'') and Created < DATE '+QUOTEDSTR(sEndDate);

  EXECUTE InsertStmt;

  SET RecCount = RowsAffected(InsertStmt);
....
....
{sql}

Regards & Tks again,
Ian
Image