0

I need to update a table based on a value derived from case logic. That case logic is created using several other tables, such as this:

CASE 
    WHEN column = 'value'  
        THEN
            COALESCE
            (
                CASE WHEN column = 'test1' THEN 'result' END,
                CASE WHEN column = 'test2' THEN 'result' END
            )
    ELSE
        column 
    END AS Derived_Column
FROM 
    table_a a
    LEFT JOIN table_b b ON a.column = b.column
    LEFT JOIN tabel_c c ON b.column = c.column

What I need to to do something like this:

UPDATE table SET column = 
( SELECT column FROM table WHERE column = <CASE STATEMENT LOGIC>)

Somehow I need to updated the column in the table filtering on the the output of Derived_Column. So I need to check against a sub query or something of that nature.

Would anyone know how to do this?

HABO
  • 15,314
  • 5
  • 39
  • 57
Zolt
  • 2,761
  • 8
  • 43
  • 60
  • 1
    Does this answer your question? [How do I UPDATE from a SELECT in SQL Server?](https://stackoverflow.com/questions/2334712/how-do-i-update-from-a-select-in-sql-server) – Isaac Mar 14 '20 at 20:22
  • Please read the first couple of paragraphs in the [tsql tag info](https://stackoverflow.com/tags/tsql/info) and [edit] your question accordingly. – Zohar Peled Mar 15 '20 at 06:13

0 Answers0