Advertisement
puggan

pnr_checkdigit.sql

Feb 1st, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.39 KB | None | 0 0
  1. CREATE FUNCTION cdigit (s CHAR(12))
  2. RETURNS TINYINT UNSIGNED DETERMINISTIC
  3. RETURN (200 - (2*SUBSTR(s,3,1) + SUBSTR(s,4,1) + 2*SUBSTR(s,5,1) + SUBSTR(s,6,1) + 2*SUBSTR(s,7,1) + SUBSTR(s,8,1) + 2*SUBSTR(s,9,1) + SUBSTR(s,10,1) + 2*SUBSTR(s,11,1) + IF(SUBSTR(s,3,1) > 4, 1, 0) + IF(SUBSTR(s,5,1) > 4, 1, 0) + IF(SUBSTR(s,7,1) > 4, 1, 0) + IF(SUBSTR(s,9,1) > 4, 1, 0) + IF(SUBSTR(s,11,1) > 4, 1, 0))) % 10;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement