IF AND ELSE STATEMENT NOT WORKING IN PRINT RESULT

Issue

This Content is from Stack Overflow. Question asked by Touchmenot

SELECT Id, FirstName, LastName, Age, Gender, Level from [dbo].[Records]


    
    
    if (@myAge BETWEEN 14 AND 16)


    UPDATE [dbo].[Records] SET Level = 'FRESHMAN' FROM [dbo].[Records] WHERE AGE BETWEEN 14 AND 16;
    
    
    ELSE IF (@myAge  BETWEEN 17 AND 19)
    
    UPDATE  [dbo].[Records] SET Level = 'SOPHOMORE' FROM [dbo].[Records] WHERE AGE BETWEEN 17 AND 19;
    

    ELSE IF (@myAge  BETWEEN 20 AND 22) 
    
    UPDATE  [dbo].[Records] SET Level = 'JUNIOR' FROM [dbo].[Records] WHERE AGE BETWEEN 20 AND 22;
    
    

    ELSE IF @myAge  BETWEEN 22 AND 25 
    
    UPDATE  [dbo].[Records] SET Level = 'SENIOR' FROM [dbo].[Records] WHERE AGE BETWEEN 23 AND 25;
    
    


    ELSE

    UPDATE  [dbo].[Records] SET Level = 'UNKNOWN' FROM [dbo].[Records] WHERE AGE IS NULL;

    
    
    END

the rusult didnt change the level column, only freshman work, how to make the else-if statement fix the right code? thanks you so much

RESULT HERE:

id: 1 Name: Santos Mark Antho Age:17 Gender:Male Level: FRESHMANenter image description here
id: 2 Name: Nonat JaysonI Age:15 Gender:Male Level: FRESHMAN
id: 3 Name: ValenciaNicoleu Age:20 Gender:Female Level: FRESHMAN
id: 4 Name: CamposJaneu Age:19 Gender:Female Level: FRESHMAN
id: 5 Name: MoralesMicahu Age:21 Gender:Female Level: FRESHMAN



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?