create procedure modul_11 (@@number varchar(15)) as begin /* **procedure to calculate modulus-11 checkdigit **procedure written 19980828 by andreas birgerson **last revision on 19981103 by andreas birgerson */ set nocount on declare @@max smallint declare @@counter smallint declare @@weight varchar(24) declare @@rest smallint select @@weight='864235978642359786423597' select @@max=datalength(@@number) select @@weight=right(@@weight,@@max) if not @@max between 4 and 20 begin raiserror('Modul-11 invalid argument length',2,-1) with seterror return end create table #f (chkdigit smallint) select @@counter=@@max+1 loop: select @@counter=@@counter-1 insert #f select (ascii(substring(@@weight,@@counter,1))-48)* (ascii(substring(@@number,@@counter,1))-48) if @@counter >1 goto loop select @@rest=sum(chkdigit)%11 from #f select "Checkdigit"= case @@rest when 0 then 5 when 1 then 0 else 11-@@rest end drop table #f set nocount off end GO GRANT EXECUTE ON MODUL_11 TO PUBLIC GO