Can I have multiple boolean expressions in the requested sql statement case?

I am trying to create a sql case case query based on a lot of boolean expressions.

for instance

select CASE a = b OR c = d OR e = f OR g = h
THEN 'x' ELSE 'y' END
from table_name

I keep getting the following error: Incorrect syntax near '='.

Am I doing something that is inherently wrong / illegal in sql, or is it something I can fix? If this is a fix, how can I do this?

Thank!

+2
source share
3 answers
select CASE when ( a = b OR c = d OR e = f OR g = h )
THEN 'x' ELSE 'y' END
from table_name

Format CASE..WHEN..THEN..ELSE..END. You were simply absent WHEN.

+3
source

I feel very stupid. I miss when after work ...

Must be

select CASE when a = b OR c = d OR e = f OR g = h
THEN 'x' ELSE 'y' END
from table_name

Then it works ...

+2
source

You have missed a WHENkeyword

SELECT 
CASE WHEN a = b OR c = d OR e = f OR g = h
THEN 'x' 
ELSE 'y' 
END
FROM table_name
+1
source

All Articles