You can use one of the expressions that WHEN has, but you cannot mix both of them.
Is a simple expression to which input_expression is compared when the simple CASE format is used. when_expression is any valid expression. The data types of input_expression and each when_expression must be the same or must be an implicit conversion.
Is the Boolean expression evaluated when using the searched CASE format. Boolean_expression is any valid Boolean expression.
You could program:
But in any case you can expect that the variable ranking is going to be compared in a boolean expression.
answered Jul 9 ’14 at 14:42
plus one: I was not aware of this syntax with individual boolean expressions DaveBoltman Jul 16 ’15 at 18:14
answered Feb 25 ’15 at 12:43
add some extra info Pramod Nikam Feb 25 ’15 at 12:48
Only answer with full query, thanks :) Alexander Derck Mar 14 ’16 at 8:39
There are already a lot of answers with respect to CASE. I will explain when and how to use CASE .
You can use CASE expressions anywhere in the SQL queries. CASE expressions can be used within the SELECT statement, WHERE clauses, Order by clause, HAVING clauses, Insert, UPDATE and DELETE statements.
A CASE expression has the following two formats:
Simple CASE expression
This compares an expression to a set of simple expressions to find the result. This expression compares an expression to the expression in each WHEN clause for equivalency. If the expression within the WHEN clause is matched, the expression in the THEN clause will be returned.
This is where the OP’s question is falling. 22978 OR 23218 OR 23219 will not get a value equal to the expression i.e. ebv.db_no. That’s why it is giving an error. The data types of input_expression and each when_expression must be the same or must be an implicit conversion.
Searched CASE expressions
This expression evaluates a set of boolean expressions to find the result. This expression allows comparison operators, and logical operators AND/OR with in each Boolean expression.
1.SELECT statement with CASE expressions
2.Update statement with CASE expression
3.ORDER BY clause with CASE expressions
4.Having Clause with CASE expression
Hope this use cases will help someone in future.