Select value if condition in SQL Server

This question already has an answer here:

  • How do I perform an IF…THEN in an SQL SELECT? 22 answers
  • SQL returning custom values based on query results 2 answers

  • 尝试案例

    SELECT   stock.name,
          CASE 
             WHEN stock.quantity <20 THEN 'Buy urgent'
             ELSE 'There is enough'
          END
    FROM stock
    

    Have a look at CASE statements
    http://msdn.microsoft.com/en-us/library/ms181765.aspx

    链接地址: http://www.djcxy.com/p/94340.html

    上一篇: 选择语句中的布尔逻辑

    下一篇: 如果在SQL Server中有条件,请选择值