SQL Case Statement

The SQL CASE Statement is a very handy little feature. 

I recently had to update several rows of a table at once and i used it to good effect. I have no idea how it will perform when it comes to large updates but for a small amount of rows it works like a charm.

Picked up from this SO thread.


Multiple update

UPDATE config
   SET config_value = CASE config_name 
                      WHEN 'name1' THEN 'value' 
                      WHEN 'name2' THEN 'value2' 
                      ELSE config_value
                      END
 WHERE config_name IN('name1', 'name2');


Comments

Popular posts from this blog

Wasted about an hour of my life on something so trivial

Connecting to AWS DynamoDb with .NET CORE

Hiding YouTube comments section