2010-03-24 124 views
5
SELECT  WO_BreakerRail.ID, indRailType.RailType, indRailType.RailCode, WO_BreakerRail.CreatedPieces, WO_BreakerRail.OutsideSource, WO_BreakerRail.Charged, WO_BreakerRail.Rejected, WO_BreakerRail.RejectedToCrop, WO_BreakerRail.Date 
FROM   indRailType LEFT OUTER JOIN 
         WO_BreakerRail ON indRailType.RailCode = WO_BreakerRail.RailCode AND WO_BreakerRail.Date = @date 

当它返回,也有在日期列,其中有来自WO_BreakerRail没有匹配行NULL值。有没有办法用@date替换那些NULL值?在LEFT OUTER替换返回null值JOIN

回答

0

是,只要使用COALESCE,例如。 COALESCE(WO_BreakerRail.Date, @date)

2

可以使用COALESCE功能(去here为MySQL文档)

COALESCE(WO_BreakerRail.Date, @date) 

,或者你可以使用一个简单IF:

IF(WO_BreakerRail.Date IS NULL, @date, WO_BreakerRail.Date) 
0

事实上,在MySQL有一个IFNULL()函数。

select 
    ifnull(wo_breakerrail.date, @date) as `date`,