Why doesn't an OR operator work inside CASE statement?

Viewed 83

I have been trying to put an OR operator in CASE statement but it doesn't work.

 Where W.Organization_ID = 
 CASE @IsAdmin OR @IsChiefEngineer 
 WHEN 1 
 THEN W.Organization_ID 
 ELSE @OrganizationID END

I want to check if any IsAdmin or IsChief engineer, either or they is 1 then Organization else @OrganizationID

3 Answers

Nearly, just alter your case statement a bit :

CASE
WHEN @IsAdmin = 1  OR @IsChiefEngineer = 1 
THEN W.Organization_ID 
ELSE @OrganizationID 
END

You can write it as follows:

Where W.Organization_ID = CASE 
    WHEN @IsAdmin = 1 OR @IsChiefEngineer = 1 
        THEN W.Organization_ID 
    ELSE @OrganizationID END

You should test every parameter "inside" the OR operator

    CASE 
       WHEN @IsAdmin = 1 OR @IsChiefEngineer = 1 
       THEN W.Organization_ID 
       ELSE @OrganizationID 
    END
Related