Conditional Processing in Oracle and SQL Server

The Transact-SQL conditional statement includes the IF and ELSE terminology. There is no ELSIF as in PL/SQL; however, multiple IF statements can be embedded within each other to achieve the same effect. For extensive conditional tests, it is recommend that you use the CASE statement.

Oracle SQL Server
DECLARE
VDEGREE_PROGRAM CHAR(1);
VDEGREE_PROGRAM_NAME VARCHAR2(20);
BEGIN
    VDEGREE_PROGRAM := 'U';
    IF VDEGREE_PROGRAM = 'U' THEN
        VDEGREE_PROGRAM_NAME :=
            'Undergraduate';
    ELSIF VDEGREE_PROGRAM = 'M' THEN
        VDEGREE_PROGRAM_NAME :=
            'Masters';
    ELSIF VDEGREE_PROGRAM = 'P' THEN
        VDEGREE_PROGRAM_NAME := 'PhD';
    ELSE VDEGREE_PROGRAM_NAME :=
            'Unknown';
    END IF;
END;
DECLARE
@VDEGREE_PROGRAM CHAR(1),
@VDEGREE_PROGRAM_NAME VARCHAR(20)
SELECT @VDEGREE_PROGRAM = 'U'
SELECT @VDEGREE_PROGRAM_NAME =
    CASE @VDEGREE_PROGRAM
        WHEN 'U' THEN 'Undergraduate'
        WHEN 'M' THEN 'Masters'
        WHEN 'P' THEN 'PhD'.
        ELSE 'Unknown'
    END

See Also
CASE IF...ELSE
Using CASE Using IF...ELSE

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.