mysql中的IF(expr1,expr2,expr3)
如果 expr1 是TRUE (expr1 <> 0 and expr1 <> NULL),则 IF()的返回值为expr2; 否则返回值则为 expr3。
在sql2005中要实现相同功能该怎么写?
------解决方案--------------------
MS SQL Server 中你可以用 case when expr1 then expr2 else expr3 end
- SQL code
USE AdventureWorks;GOSELECT ProductNumber, Category = CASE ProductLine WHEN 'R' THEN 'Road' WHEN 'M' THEN 'Mountain' WHEN 'T' THEN 'Touring' WHEN 'S' THEN 'Other sale items' ELSE 'Not for sale' END, NameFROM Production.ProductORDER BY ProductNumber;GO