首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql2005如何实现mysql中的if()函数

2012-02-20 
sql2005怎么实现mysql中的if()函数mysql中的IF(expr1,expr2,expr3)如果 expr1 是TRUE (expr1 0 and exp

sql2005怎么实现mysql中的if()函数
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 

热点排行