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