Last active
August 29, 2015 14:05
-
-
Save JRGGRoberto/b5b7201077088e4bfaba to your computer and use it in GitHub Desktop.
Gerando hierarquina das organizações no vtiger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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