2010-03-24 188 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`,