How do I perform an IF...THEN
in an SQL SELECT
statement?
For example:
SELECT IF(Obsolete = 'N' OR InStock = 'Y' ? 1 : 0) AS Saleable, * FROM Product
How do I perform an IF...THEN
in an SQL SELECT
statement?
For example:
SELECT IF(Obsolete = 'N' OR InStock = 'Y' ? 1 : 0) AS Saleable, * FROM Product
Simple if-else statement in SQL Server:
Nested If...else statement in sql server -
For those who uses SQL Server 2012, IIF is a feature that has been added and works as an alternative to Case statements.
You can find some nice examples in The Power of SQL CASE Statements, and I think the statement that you can use will be something like this (from 4guysfromrolla):