SQL Case statement: condition

This is a good tool to have in your SQL query toolbox: Sql CASE

From http://www.tizag.com/sqlTutorial/sqlcase.php

"SQL CASE is a very unique conditional statement providing if/then/else logic for any ordinary SQL command, such as SELECT or UPDATE. It then provides when-then-else functionality (WHEN this condition is met THEN do_this)."

Sample:

"USE mydatabase;

SELECT product,
      'Status' = CASE
        WHEN quantity > 0 THEN 'in stock'
        ELSE 'out of stock'
        END
FROM dbo.inventory;"