CREATE FUNCTION dbo.abz(@number1 INT)
RETURNS INT
WITH RETURNS NULL ON NULL INPUT
AS
BEGIN
IF @number1 < 0
BEGIN
RETURN -1 * @number1
END
IF @number1 = 0
BEGIN --line21
RETURN 0
END
IF @number1 > 0
BEGIN
RETURN @number1
END
END
I get this error when this code is run:
Msg 156, Level 15, State 1, Server DB, Procedure abz, Line 21 Incorrect syntax near the keyword 'IF'.
Why? There's not even an IF statement on that line.
abs()function, which does the same thing.The last statement included within a function must be a return statement, which makes sense since not all your paths of execution return something.