How do I perform an IF…THEN in an SQL SELECT?

前端 未结 30 1827
梦如初夏
梦如初夏 2020-11-21 22:50

How do I perform an IF...THEN in an SQL SELECT statement?

For example:

SELECT IF(Obsolete = \'N\' OR InStock = \'Y\' ? 1 :          


        
30条回答
  •  忘了有多久
    2020-11-21 23:12

    For those who uses SQL Server 2012, IIF is a feature that has been added and works as an alternative to Case statements.

    SELECT IIF(Obsolete = 'N' OR InStock = 'Y', 1, 0) AS Salable, *
    FROM   Product 
    

提交回复
热议问题