$ curl cheat.sh/
/*
 * The `CASE` statement is the closest to IF in SQL and is supported on
 * all versions of SQL Server.
 */

 SELECT CAST(
              CASE
                   WHEN Obsolete = 'N' or InStock = 'Y'
                      THEN 1
                   ELSE 0
              END AS bit) as Saleable, *
 FROM Product

/*
 * You only need to use the `CAST` operator if you want the result as a
 * Boolean value. If you are happy with an `int`, this works:
 */

 SELECT CASE
             WHEN Obsolete = 'N' or InStock = 'Y'
                THEN 1
                ELSE 0
        END as Saleable, *
 FROM Product

/*
 * `CASE` statements can be embedded in other `CASE` statements and even
 * included in aggregates.
 * 
 * SQL Server Denali (SQL Server 2012) adds the [IIF][1] statement which
 * is also available in [access][2] (pointed out by [Martin Smith][3]):
 */

 SELECT IIF(Obsolete = 'N' or InStock = 'Y', 1, 0) as Saleable, * FROM Product

/*
 *   [1]: http://msdn.microsoft.com/en-
 * us/library/hh213574%28v=sql.110%29.aspx
 *   [2]: http://www.techonthenet.com/access/functions/advanced/iif.php
 *   [3]: https://stackoverflow.com/questions/63447/how-do-you-perform-
 * an-if-then-in-an-sql-select/6769805#6769805
 * 
 * [Darrel Miller] [so/q/63447] [cc by-sa 3.0]
 */

$
Follow @igor_chubin cheat.sh