Avatar of Bobby X
Bobby X
Flag for United States of America

asked on 

SQL Case Statements Evaluation

Hi,

Could someone please tell me what's wrong with these case statements (see below). Please see my comments below in the 'where' clause:

select c.Id, c.first_name, c.last_name, c.email, c.phone
from customers c
where c.type = 2
and (
    case
        when ((c.first_name like 'John%' and c.last_name like '%Christian%') or c.last_name like '%John Christian%')
            THEN 1 -- If this returns 1, I want the rest of the 'else' block below to skip, how do I do that?
        else -- This 'else' block for some reason is always running even though tht above 'THEN' returns 1
            case
                when (c.first_name like 'John%' or c.last_name like '%Christian%')
                    then 1
                    else 0
            end
    end = 1
)

Many thanks in advance.
SQL* T-SQLMicrosoft SQL Server

Avatar of undefined
Last Comment
slightwv (䄆 Netminder)

8/22/2022 - Mon