In 2018, on a test about databases (which I have failed multiple times) at my university, they had this task:

Napisati T-SQL funkciju koja prima 3 realna broja, te kao rezultat vraća onaj broj koji ima najveću apsolutnu vrijednost. Ako slučajno istu najveću apsolutnu vrijednost imaju dva ili tri broja potrebno je vratiti zbroj tih brojeva.

That is:

Write a T-SQL function that accepts 3 real numbers, and as a result it returns the number that has the biggest absolute value. If accidentally the same biggest absolute value is had by two or three numbers it is necessary to return the sum of those numbers.

How would you solve that?

Here is my attempt, I do not know if it is correct nor how to actually test it on my computer:

`CREATE FUNCTION max_abs3(@x, @y, @z DECIMAL) RETURNS DECIMAL`

BEGIN

IF ABS(@x)=ABS(@y) AND ABS(@y)=ABS(@z)

BEGIN

RETURN @x+@y+@z;

END;

IF ABS(@x)=ABS(@y) AND ABS(@x)>ABS(@z)

BEGIN

RETURN @x+@y;

END;

IF ABS(@x)=ABS(@z) AND ABS(@x)>ABS(@y)

BEGIN

RETURN @x+@z;

END;

IF ABS(@y)=ABS(@z) AND ABS(@y)>ABS(@x)

BEGIN

RETURN @y+@z;

END;

IF ABS(@x)>ABS(@y) AND ABS(@x)>ABS(@z)

BEGIN

RETURN @x;

END;

IF ABS(@y)>ABS(@z) AND ABS(@y)>ABS(@x)

RETURN @y;

END;

RETURN @z;

END;

I have only managed to install SQLite on my computer, and it apparently does not support custom SQL functions.