Do tej pory doszedłem do czegoś takiego:
create trigger wwwww on osoby
for insert
as
declare @pesel varchar(11)
if
( (((cast(substring(@pesel,1,1) as tinyint)*9)
+(cast(substring(@pesel,2,1) as bigint)*7)
+(cast(substring(@pesel,3,1) as bigint)*3)
+(cast(substring(@pesel,4,1) as bigint)*1)
+(cast(substring(@pesel,5,1) as bigint)*9)
+(cast(substring(@pesel,6,1) as bigint)*7)
+(cast(substring(@pesel,7,1) as bigint)*3)
+(cast(substring(@pesel,8,1) as bigint)*1)
+(cast(substring(@pesel,9,1) as bigint)*9)
+(cast(substring(@pesel,10,1) as bigint)*7) ) % 10)
= 0 and (cast(substring(@pesel,11,1) as bigint)*1 ) =0)
or
10-(((cast(substring(@pesel,1,1) as tinyint)*9)
+(cast(substring(@pesel,2,1) as bigint)*7)
+(cast(substring(@pesel,3,1) as bigint)*3)
+(cast(substring(@pesel,4,1) as bigint)*1)
+(cast(substring(@pesel,5,1) as bigint)*9)
+(cast(substring(@pesel,6,1) as bigint)*7)
+(cast(substring(@pesel,7,1) as bigint)*3)
+(cast(substring(@pesel,8,1) as bigint)*1)
+(cast(substring(@pesel,9,1) as bigint)*9)
+(cast(substring(@pesel,10,1) as bigint)*7) ) % 10)
=(cast(substring(@pesel,11,1) as bigint)*1 )
rollback
wagi jakie zastosowałem to 9,7,3,1-dla wyeliminowania przypadku kiedy mod =10
Przykład dla numeru PESEL 44051401358:
14 + 34 + 70 + 95 + 11 + 34 + 70 + 91 + 13 + 35 = 101
Wyznaczamy resztę z dzielenia sumy przez 10:
101:10 = 10 reszta = 1
Jeżeli reszta = 0, to cyfra kontrolna wynosi 0. Jeżeli reszta ≠ 0, to cyfra kontrolna będzie uzupełnieniem reszty do 10, czyli w podanym przykładzie jest to cyfra 9.
10 - 1 = 9
Wynik 9 nie jest równy ostatniej cyfrze numeru PESEL, czyli 8, więc numer jest błędny.
więc pierwsza długa część sprawdza że jeśli reszta jest równa zero czy jest równa cyfrze kontrolnej,która powinna być zero
druga częśc kodu od 10 odejmuje modulo i sprawdza czy jest równe cyfrze kontrolnej
Wyzwalacz jednak przepuszcza każdy pesel,dlaczego? Czego brakuje w tym kodzie bo już nie mam pomysłu