Menu Bar

Monday, January 16, 2012

CASE in point, redux


"My friends, you bow to no one" - Aragorn, to the hobbits, Return of the King
In a recent post made for my reference, I came posted the syntax for the SQL Server CASE statement, because I always forget some of the finer points of less used syntax.

Well, it just so happens that I also found myself recently needing the syntax for a CASE statement used inside an update.

In keeping with the other posting, this seems a mighty fine place to record such a thing


update mytable
set col1 =
  (CASE
     WHEN
        (condition)
     THEN
        (value)
     ELSE
        (other value)
     END
  )
where column = value

Another quickie, mainly for my enjoyment at some stage down the road!

No comments:

Post a Comment