a:1:{i:0;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:21:"fv2_greige_createngos";s:4:"nome";s:9:"onExecute";s:4:"tipo";s:1:"E";s:5:"parms";s:0:"";s:6:"codigo";s:1065:"//TESTED AND WORKS THROUGH LINE 61-cs 05/16/2016

$trunkit="Truncate ngo";
sc_exec_sql($trunkit);
sc_exec_sql("
INSERT INTO ngo 
(p_o_number) 
SELECT 
(p_o_number)
FROM grpcs
");
sc_exec_sql("
DELETE a
FROM ngo as a, ngo as b
WHERE
          (a.p_o_number = b.p_o_number)
      AND a.ID2 < b.ID2
");

sc_exec_sql("
UPDATE ngo
	SET
	invoice = concat('X',p_o_number),adate = curdate()
");
sc_exec_sql("
UPDATE grpcs
	SET
	invoice = concat('X',p_o_number)
");

//Fill in blank fields in NGO from greigepo
$update_ngo_greigepo= 
"
UPDATE ngo c
INNER JOIN 
(SELECT p_o_number, mill,new_style,ship_to
  FROM greigepo
  GROUP BY p_o_number)
x ON c.p_o_number = x.p_o_number
SET c.mill=x.mill,c.style=x.new_style,c.location=x.ship_to
";
sc_exec_sql($update_ngo_greigepo);

//Fill in date from max(grpcs date)
$update_ngo_grpcs= 
"
UPDATE ngo c
INNER JOIN 
(SELECT p_o_number, max(adate)as ldate
  FROM grpcs
  GROUP BY p_o_number)
x ON c.p_o_number = x.p_o_number
SET c.date=x.ldate
";
sc_exec_sql($update_ngo_grpcs);
";}}