Question re UPDATE

Giganews Newsgroups
Subject: Question re UPDATE
Posted by:  Rav (Pau…@cais.com)
Date: Thu, 23 Dec 2010

Using SQL 2005.  Consider the following statements:

UPDATE my_table SET my_field = 4 WHERE my_field = 197
UPDATE my_table SET my_field = 5 WHERE my_field = 199
UPDATE my_table SET my_field = 6 WHERE my_field = 201
UPDATE my_table SET my_field = 8 WHERE my_field = 203

Is there a way to do that with ONE UPDATE statement?  Although the
following isn't valid SQL syntax, it expresses what I want to do:

UPDATE my_table
    SET my_field = 4 WHERE my_field = 197
  ,SET my_field = 5 WHERE my_field = 199
  ,SET my_field = 6 WHERE my_field = 201
  ,SET my_field = 8 WHERE my_field = 203

Is there a simple way I can do what I want with, for example, some sort
of CASE statement?  I couldn't figure out how.

Thanks.

Replies