To calculate bank routing check digit (digit #9 is used to validate 8-digit bank routing (ABA) number)

(for more scripts --> goto http://www.siccolo.com/articles.html)

2004-10-01 (first published: 2002-06-20)

15,390 reads

To calculate bank routing check digit (digit #9 is used to validate 8-digit bank routing (ABA) number)

(for more scripts --> goto http://www.siccolo.com/articles.html)

CREATE FUNCTION create_check_digit (@routing_number char(8) ) returns int as begin declare @digit int ,@sum_digit int declare @check_digit int set @check_digit=0 --1 set @digit =convert(int, substring(@routing_number, 1, 1)) set @sum_digit = @digit*3 --2 set @digit =convert(int, substring(@routing_number, 2, 1)) set @sum_digit = @sum_digit + @digit*7 --3 set @digit =convert(int, substring(@routing_number, 3, 1)) set @sum_digit = @sum_digit + @digit*1 --4 set @digit =convert(int, substring(@routing_number, 4, 1)) set @sum_digit = @sum_digit + @digit*3 --5 set @digit =convert(int, substring(@routing_number, 5, 1)) set @sum_digit = @sum_digit + @digit*7 --6 set @digit =convert(int, substring(@routing_number, 6, 1)) set @sum_digit = @sum_digit + @digit*1 --7 set @digit =convert(int, substring(@routing_number, 7, 1)) set @sum_digit = @sum_digit + @digit*3 --8 set @digit =convert(int, substring(@routing_number, 8, 1)) set @sum_digit = @sum_digit + @digit*7 if (@sum_digit % 10) > 0 set @check_digit = 10 - (@sum_digit % 10) return @check_digit end