2017-12-31 51 views

Antwort

0

können Sie verwenden:

Methode für luhn algo:

CREATE FUNCTION [dbo].[F_CHECK_LUHN] (@DATA VARCHAR(32)) 
RETURNS BIT AS 

BEGIN 
-- valeurs limites 
IF @DATA IS NULL OR @DATA = '' RETURN NULL; 

DECLARE @Cpt INT = 0; 
declare @C CHAR(1); 
declare @Chiffre integer=0; 
declare @Somme integer=0; 
declare @parity integer; 
set @parity=LEN(@DATA) % 2; 

WHILE @Cpt < LEN(@DATA) 
BEGIN 

    SET @C = SUBSTRING(@DATA, @Cpt+1, 1); 

    IF @C NOT BETWEEN '0' AND '9' RETURN NULL; 

    set @Chiffre=CAST(@C AS SMALLINT); 

    if ((@Cpt % 2) [email protected]) 
    begin 
    set @[email protected]*2; 

     if (@Chiffre>9) 
     begin 
     set @[email protected]; 
     end; 

    end; 

    set @[email protected][email protected]; 

    SET @Cpt = @Cpt + 1; 
END; 

RETURN CASE WHEN @Somme % 10 = 0 THEN 1 ELSE 0 end ; 

END; 

Funktion zur Steuerung SIRENE:

CREATE FUNCTION [dbo].[F_IsSiren](@DATA VARCHAR(9)) 
RETURNS BIT AS 

BEGIN 

if @DATA is null or len(@DATA)<>9 or @DATA='000000000' return 0; 

DECLARE @Result bit; 

select @Result=dbo.F_CHECK_LUHN(@DATA) 

return @Result; 
END ; 

Funktion zur Steuerung SIRET:

CREATE FUNCTION [dbo].[F_IsSiret](@DATA VARCHAR(14)) 
RETURNS BIT AS 

BEGIN 

if @DATA is null or len(@DATA)<>14 or @DATA='00000000000000' return 0; 

DECLARE @Result bit; 
DECLARE @ValidLuhn bit; 


set @ValidLuhn=dbo.F_CHECK_LUHN(@DATA); 

--Cas particuliere de la poste, la somme des chiffres doit être modulo 5 
if @ValidLuhn=0 and left(@DATA, 9)='356000000' 
begin 
DECLARE @Cpt INT = 0; 
declare @C CHAR(1); 
declare @Chiffre integer=0; 
declare @Somme integer=0; 

WHILE @Cpt < LEN(@DATA) 
BEGIN 

    SET @C = SUBSTRING(@DATA, @Cpt+1, 1); 

    IF @C NOT BETWEEN '0' AND '9' 
    begin 
    set @Somme=-1; 
    break; 
    end 

    set @Chiffre=CAST(@C AS SMALLINT); 

    set @[email protected][email protected]; 

    SET @Cpt = @Cpt + 1; 
END; 

if ((@Somme % 5) =0) 
set @Result=1; 
else 
set @Result=0; 


end 
else 
begin 
--Verification algo de luhn 
select @[email protected]; 
end 

return @Result; 
END ; 
Verwandte Themen