Cases in SQL syntax

I've never seen this SQL syntax:

    select
        column1,
        case
            when table1.column1 is not null then 1
            when
table2.column1 is not null then 2
            when
table0.column1 is not null then 0
        end as column_nameX,
    ...

Have you?

3 thoughts on “Cases in SQL syntax”

  1. yes, I have
    and I use it when appropriate. Your example is not very good but this could be used widely in views to facilitate data understanding. For instance if you have several bit fields for describe why some operation failed you could add calculated column with IF statement of CASE statement to present a better result.
    Of course this is not very good in large databases because filtering by this column will cause full table scan

  2. Hey. If a free society cannot help the many who are poor, it cannot save the few who are rich.
    I am from Cape and also now am reading in English, give please true I wrote the following sentence: "Retirement, risks should draw up to their payment - at least that's the superintendency."

    Regards 🙁 Early retirement forum.

Leave a Reply

Your email address will not be published.

Notify me of followup comments via e-mail. You can also subscribe without commenting.

This site uses Akismet to reduce spam. Learn how your comment data is processed.