Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. CREATE DEFINER=`root`@`%` FUNCTION `Validar_Nit`(tcNit varchar(15)) RETURNS int(11)
  2. BEGIN
  3. DECLARE lcDato, lcChar VARCHAR(15) DEFAULT '';
  4. DECLARE lnItem, lnSuma, lnRetorno INT DEFAULT 0;
  5. SET lcDato := RIGHT(CONCAT(SPACE(15), TRIM(tcNit)), 15);
  6. REPEAT
  7. SET lnItem := lnItem + 1;
  8. SET lcChar := SUBSTR(lcDato FROM lnItem FOR 1);
  9. SET lnSuma := lnSuma + (lcChar * ELT(lnItem, 71, 67, 59, 53, 47, 43, 41, 37, 29, 23, 19, 17, 13, 7, 3));
  10. UNTIL lnItem = 15
  11. END REPEAT;
  12. SET lnSuma := MOD(lnSuma, 11);
  13. IF lnSuma = 0 OR lnSuma = 1 THEN
  14. SET lnRetorno := lnSuma;
  15. ELSE
  16. SET lnRetorno := 11 - lnSuma;
  17. END IF;
  18. RETURN lnRetorno;
  19. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement