473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

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
0 1798

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

Similar topics

5
by: Detlef Jockheck | last post by:
Hi, I would like to check if a string contains a valid date format (Format: "dd.mm.yyyy") or not. What is the best way to do this. regexp? At the moment it would be sufficient to check for...
0
by: anaxamandr | last post by:
Hi. I have a long loop in ASP that performs a rather lengthy calculation. I would love for my users to be able to stop that calculation, if they so choose, mid way through the process. I attempted...
3
by: Ivan | last post by:
Hi, how to filter out non-digit chars when user writes text to System.Windows.Forms.TextBox? Thanks, Iavmn
35
by: pinkfloydhomer | last post by:
How do I check if a string contains (can be converted to) an int? I want to do one thing if I am parsing and integer, and another if not. /David
3
by: kathy | last post by:
I want to know what is the easy way to check if a string is a number or not? the number can be int, float, double, scientific,... what is the easy way for only interger?
3
by: linq936 | last post by:
I have some algorithm dealing with unsigned int calculation a lot, I am trying to add some check for overflow. The initial thinking was very easy, just do something like this, int...
11
by: balakrishnan.dinesh | last post by:
hi frnds, Im having two 20digit numbers, But while comparing those it is giiving wrong ouput in javascript. for example here is my code, my secanrio is , ~ If first 20 digit number is...
28
by: beach.dk | last post by:
Hi, I'm trying to implement a simple hash algorith called rs_hash in javascript, but I cannot get a correct result. In c the code looks like this:
13
by: Shirsoft | last post by:
I have a 32 bit intel and 64 bit AMD machine. There is a rounding error in the 8th digit. Unfortunately because of the algorithm we use, the errors percolate into higher digits. C++ code is...
5
by: upyzl | last post by:
#include <stdio.h> #define digit 21 int main() { int a, b, max; int i = 0; int j = 0; int x = { 0 }; int y = { 0 };
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.