Solved

11-Proef

  • 14 December 2020
  • 2 replies
  • 123 views

Badge +2

Has anybody implemented the “11-Proef” for BSN numbers, and is willing to share the code please?

Since this is a typical Dutch question:

Heeft iemand al eens een 11-proef gebouwd voor burgerservicenummers, of eventueel bankrekeningnummers? 

(Voor mij was de laatste keer 25-30 jaar geleden in BASIC en COBOL….)

https://nl.wikipedia.org/wiki/Elfproef

icon

Best answer by Erwin Ekkel 14 December 2020, 10:51

View original

This topic has been closed for comments

2 replies

Userlevel 6
Badge +16

Hello Theo,

I have not, but the basic logic seems to be multiply number by position add the numbers and if BSN multiply last number by -1. Then check if the result is a positive integer (bigger than 0). 

The code below should do the trick. You can test it with the example BSN numbers 111222333 and 123456782

For bank account you need to remove the -1 part. 

 

declare @int int
declare @position int
declare @check int
set @position = 1
set @check = 0
set @int = 111222333 
;
while @position < 10
begin
   set @check += (select SUBSTRING(cast(@int as varchar),@position,1) * case when (10-@position) = 1 then -1 else (10-@position) end)
   ;
   set @position += 1 
end
;
if (@check / 11.0) = cast(@check / 11 as int)
and (@check / 11.0) <> 0
begin
 select 'true'
end
else
begin
 select 'false'
end

Badge +2

Thank you very much! Works great.