elfproef-sql-function
In MySQL:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
CREATE FUNCTION fnElfProef (accountNr INT)
RETURNS BOOLEAN
BEGIN
DECLARE i, totaal INT DEFAULT 0;
WHILE i < 9 DO
SET i = i+1;
SET totaal = totaal+(i*(accountNr%10));
SET accountNr = FLOOR(accountNr/10);
END WHILE;
RETURN (totaal%11) = 0;
END
RETURNS BOOLEAN
BEGIN
DECLARE i, totaal INT DEFAULT 0;
WHILE i < 9 DO
SET i = i+1;
SET totaal = totaal+(i*(accountNr%10));
SET accountNr = FLOOR(accountNr/10);
END WHILE;
RETURN (totaal%11) = 0;
END
In SQL Server:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
CREATE FUNCTION fnElfProef (@accountNr INT)
RETURNS BIT
AS
BEGIN
DECLARE @i INT
SELECT @i = 0
DECLARE @total INT
SELECT @total = 0
WHILE @i < 9 BEGIN
SELECT @i = @i+1
SELECT @total = @total+(@i*(@accountNr%10))
SELECT @accountNr = @accountNr/10
END
IF (@total%11) = 0 BEGIN
RETURN 1
END
RETURN 0
END
RETURNS BIT
AS
BEGIN
DECLARE @i INT
SELECT @i = 0
DECLARE @total INT
SELECT @total = 0
WHILE @i < 9 BEGIN
SELECT @i = @i+1
SELECT @total = @total+(@i*(@accountNr%10))
SELECT @accountNr = @accountNr/10
END
IF (@total%11) = 0 BEGIN
RETURN 1
END
RETURN 0
END
Ook nog maar voor Postgre:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
CREATE OR REPLACE FUNCTION fnElfProef (accountNrIn INT)
RETURNS BOOLEAN
AS
$function$
DECLARE i INT; total INT; accountNr INT;
BEGIN
accountNr := accountNrIn;
i := 0;
total := 0;
WHILE i < 9 LOOP
i := i+1;
total := total+(i*(accountNr%10));
accountNr := accountNr/10;
END LOOP;
RETURN (total%11) = 0;
END
$function$ LANGUAGE plpgsql;
RETURNS BOOLEAN
AS
$function$
DECLARE i INT; total INT; accountNr INT;
BEGIN
accountNr := accountNrIn;
i := 0;
total := 0;
WHILE i < 9 LOOP
i := i+1;
total := total+(i*(accountNr%10));
accountNr := accountNr/10;
END LOOP;
RETURN (total%11) = 0;
END
$function$ LANGUAGE plpgsql;