Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Add Check Digit (LUHN)

By Ed Klichinsky,

If you ever need to create a credit card like number this stored procedure is for you.

Most credit cards contain a check digit, which is the digit at the end of the credit card number.

To generate the check digit, the LUHN formula is applied to the number. To validate the credit-card number, the check digit is figured into the formula.

Here's how the algorithm works for verifying credit cards; the math is quite simple:

1) Starting with the second to last digit and moving left, double the value of all the alternating digits.

2) Starting from the left, take all the unaffected digits and add them to the results of all the individual digits from step 1. If the results from any of the numbers from step 1 are double digits, make sure to add the two numbers first (i.e. 18 would yield 1+8). Basically, your equation will look like a regular addition problem that adds every single digit.

3) The total from step 2 must end in zero for the credit-card number to be valid.

Additional resources:
http://www.webopedia.com/TERM/L/Luhn_formula.html
http://www.beachnet.com/~hstiles/cardtype.html
http://euro.ecom.cmu.edu/resources/elibrary/everycc.htm

Total article views: 423 | Views in the last 30 days: 1
 
Related Articles
SCRIPT

Credit Card Number Validation Escalar Function

Evaluate credit card numbers based on ISO 2894 algorithm.

SCRIPT

How to calculate the check digit for a UCC/EAN code

Function that implements the algorithm for calculating the check digit for a UCC/EAN code

FORUM

How to add "dot" after every three digits in a number in sql 2005

How to add "dot" after every three digits in a number in sql 2005

FORUM

mod 10 weights 1, 2

check digit calcualtion

FORUM

Check given number

how to check the given number is decimal

Tags
miscellaneous    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones