Skip to content

Instantly share code, notes, and snippets.

@JRGGRoberto
Last active August 29, 2015 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JRGGRoberto/b5b7201077088e4bfaba to your computer and use it in GitHub Desktop.
Save JRGGRoberto/b5b7201077088e4bfaba to your computer and use it in GitHub Desktop.
Gerando hierarquina das organizações no vtiger
DROP PROCEDURE IF EXISTS vtigercrm540.hierarquia;
CREATE PROCEDURE vtigercrm540.hierarquia()
BEGIN
DECLARE v_finished INTEGER DEFAULT 0;
DECLARE v_filho int;
DECLARE v_pai int;
DEClARE cur CURSOR FOR
select
f.accountid,
p.accountid
from vtigercrm540.vtiger_account f
inner join vtigercrm540.vtiger_account p
on concat(SUBSTRING_INDEX(f.account_no,'.',1),'.0') = p.account_no
where
SUBSTRING_INDEX(f.ots_party_number,'.',-1) > 0
and f.accounttype = 'Mediador'
;
DECLARE CONTINUE HANDLER
FOR NOT FOUND SET v_finished = 1;
OPEN cur;
get_cur: LOOP
FETCH cur INTO v_filho, v_pai;
IF v_finished = 1 THEN
LEAVE get_cur;
END IF;
update vtigercrm540.vtiger_account set parentid = v_pai where accountid = v_filho;
END LOOP get_cur;
CLOSE cur;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment