Skip to content
Advertisement

SQL Case Statement: Set the default value for an Case

this time I need an explanation for SQL. I have seen on the internet now nothing special and maybe I have a thinking error.

I have a case statement and now I want to ” filter ” it in different ways. Specifically I have a question, whether it is possible to provide rows directly with the “ELSE Value” of the case, without writing this itself?

The example is with the word “Pflaume”, this contains the letter ‘e’ and is therefore recognized by the ‘e’ case. But I want to assign the DEFAULT value ‘default’ to this case.

Thank you and have a nice day

Advertisement

Answer

Since cases are tested in order, you can check for this case before the LIKE '%e%' case.

In general, order your cases in order of specificity — put the exceptions first, then the general cases.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement