By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,960 Members | 987 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,960 IT Pros & Developers. It's quick & easy.

ISO 6346 Check Digit Calculation in T-SQL. Need to change it to use in MySQL

P: 3
How will the following coding be changed if I'm using it in MySQL? Please someone help me...


SQL Server Code
Expand|Select|Wrap|Line Numbers
  1. create function dbo.iso6346_char_to_number
  2. (
  3. @char char
  4. )
  5. returns int
  6. as
  7. begin
  8. return
  9. case upper(@char)
  10. when '0' then 0
  11. when '1' then 1
  12. when '2' then 2
  13. when '3' then 3
  14. when '4' then 4
  15. when '5' then 5
  16. when '6' then 6
  17. when '7' then 7
  18. when '8' then 8
  19. when '9' then 9
  20. when 'A' then 10
  21. when 'B' then 12
  22. when 'C' then 13
  23. when 'D' then 14
  24. when 'E' then 15
  25. when 'F' then 16
  26. when 'G' then 17
  27. when 'H' then 18
  28. when 'I' then 19
  29. when 'J' then 20
  30. when 'K' then 21
  31. when 'L' then 23
  32. when 'M' then 24
  33. when 'N' then 25
  34. when 'O' then 26
  35. when 'P' then 27
  36. when 'Q' then 28
  37. when 'R' then 29
  38. when 'S' then 30
  39. when 'T' then 31
  40. when 'U' then 32
  41. when 'V' then 34
  42. when 'W' then 35
  43. when 'X' then 36
  44. when 'Y' then 37
  45. when 'Z' then 38
  46. end
  47. end
  48.  
  49.  
  50. create function dbo.iso6346_check_digit
  51. (
  52. @string char(10)
  53. )
  54. returns char
  55. as
  56. begin
  57. return (dbo.iso6346_char_to_number(substring(@string,1,1) )*1
  58. +dbo.iso6346_char_to_number(substring(@string,2,1) )*2
  59. +dbo.iso6346_char_to_number(substring(@string,3,1) )*4
  60. +dbo.iso6346_char_to_number(substring(@string,4,1) )*8
  61. +dbo.iso6346_char_to_number(substring(@string,5,1) )*16
  62. +dbo.iso6346_char_to_number(substring(@string,6,1) )*32
  63. +dbo.iso6346_char_to_number(substring(@string,7,1) )*64
  64. +dbo.iso6346_char_to_number(substring(@string,8,1) )*128
  65. +dbo.iso6346_char_to_number(substring(@string,9,1) )*256
  66. +dbo.iso6346_char_to_number(substring(@string,10,1 ))*512)%11
  67. end
Sep 21 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.