Replace Default Null Values Returned From Left Outer Join

后端 未结 3 866
夕颜
夕颜 2020-12-07 19:40

I have a Microsoft SQL Server 2008 query that returns data from three tables using a left outer join. Many times, there is no data in the second and third tables and so I g

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 20:21

    In case of MySQL or SQLite the correct keyword is IFNULL (not ISNULL).

     SELECT iar.Description, 
          IFNULL(iai.Quantity,0) as Quantity, 
          IFNULL(iai.Quantity * rpl.RegularPrice,0) as 'Retail', 
          iar.Compliance 
        FROM InventoryAdjustmentReason iar
        LEFT OUTER JOIN InventoryAdjustmentItem iai  on (iar.Id = iai.InventoryAdjustmentReasonId)
        LEFT OUTER JOIN Item i on (i.Id = iai.ItemId)
        LEFT OUTER JOIN ReportPriceLookup rpl on (rpl.SkuNumber = i.SkuNo)
    WHERE iar.StoreUse = 'yes'
    

提交回复
热议问题