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

前端 未结 30 1798
梦如初夏
梦如初夏 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:11

    SELECT 1 AS Saleable, *
      FROM @Product
     WHERE ( Obsolete = 'N' OR InStock = 'Y' )
    UNION
    SELECT 0 AS Saleable, *
      FROM @Product
     WHERE NOT ( Obsolete = 'N' OR InStock = 'Y' )
    

提交回复
热议问题