Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. USE `veeva_new`;
  2.  
  3. DELIMITER $$
  4.  
  5. DROP TRIGGER IF EXISTS veeva_new.address_vod__c_ai$$
  6. USE `veeva_new`$$
  7. CREATE DEFINER=`root`@`localhost` TRIGGER `veeva_new`.`address_vod__c_ai` AFTER INSERT ON `address_vod__c` FOR EACH ROW
  8. BEGIN
  9. DECLARE vCount INT(6) DEFAULT 0;
  10. SET vCount=(SELECT COUNT(*) FROM pdone.targets WHERE targets.veeva_account_id=NEW.account_vod__c);
  11. IF (vCount>0) THEN
  12. SET @TargetLastMod=(SELECT targets.lastSyncAt FROM pdone.targets WHERE targets.veeva_account_id=NEW.account_vod__c LIMIT 0,1);
  13.  
  14. UPDATE pdone.targets
  15. JOIN address_vod__c AS avc ON (address_vod__c.account_vod__c = NEW.account_vod__c AND targets.veeva_account_id=NEW.account_vod__c)
  16. SET
  17. `address1` = avc.address1,
  18. `address2` = avc.address2,
  19. `city` = avc.city,
  20. `state` = avc.state,
  21. `zip` = avc.zip,
  22. `phone` = avc.phone,
  23. `fax` = avc.fax,
  24. `lastSyncAt` = NOW(),
  25. `updatedAt` = NOW()
  26. WHERE address_vod__c.account_vod__c = NEW.account_vod__c
  27. AND external_id_vod__c IS NOT NULL
  28. AND address_vod__c.primary_vod__c = 1
  29. AND account.recordtypeid COLLATE utf8_general_ci IN (SELECT id FROM veevan.recordtype WHERE name = 'Professional_vod');
  30.  
  31. END IF;
  32. END$$
  33. DELIMITER ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement