mercredi 16 décembre 2020

mssql server - Incorrect syntax near the keyword 'ELSE'

I have problem with ELSE function

Here is my code:

DECLARE @a AS int = 2;
DECLARE @b AS int = 4;
DECLARE @c AS int = 1;
DECLARE @delta AS int;
DECLARE @x0 AS int;
DECLARE @x1 AS int;
DECLARE @x2 AS int;

BEGIN
    SET @delta = POWER(@b, 2) - 4 * @a * @c
            IF @delta > 0
                SET @x1 = -@b - SQRT(@delta) / 2 * @a
                SET @x2 = -@b + SQRT(@delta) / 2 * @a
                PRINT 'Delta equals: ' + CAST(@delta AS varchar) + 'x1: ' + CAST(@x1 AS varchar) + 'x2: ' + CAST(@x2 AS varchar);
            ELSE IF @delta = 0
                SET @x0 = -@b / 2 * @a
                PRINT 'Delta equals: ' + CAST(@delta AS varchar) + 'x0: ' + CAST(@x0 AS varchar);
            ELSE
END

Errors I get:

Msg 156, Level 15, State 1, Line 15 Incorrect syntax near the keyword 'ELSE'.

Msg 156, Level 15, State 1, Line 18 Incorrect syntax near the keyword 'ELSE'.

Aucun commentaire:

Enregistrer un commentaire