Access query – replace null with zero in sum for calculation SQL syntax error

  Kiến thức lập trình

Been looking at this simple SQL too long for an ACCESS database query. When I try to run/save, get message AS statement syntax error. I have a query that is pulling data from 3 tables. A product list (master list of all products), incoming inventory (entry of all incoming quantity), and product sales (download of sales data from our POS). My goal with this query is to calculate the on-hand quantity by creating a list of all products that sums quantity incoming inventory and product sales. A formula than calculates difference as incoming inventory – product sales. So if no incoming inventory but have sales should have negative variance. My issue is that my Incoming Inventory is being seen as Null and needs to be seen as a Zero for calculating variance. Any help on how I need to edit this SQL would be greatly appreciated.

SELECT
    [Product List].Barcode,
    [Product List].[Product Description],
    IFF((SUM([Incoming Inventory].[Total Quantity]) IS NULL, 0, (Sum([Incoming Inventory].[Total Quantity]) AS [SumOfTotal Quantity],
    Sum([Product Sales].[Sum of Product Quantity]) AS [SumOfSum of Product Quantity]),
    [Total Quantity]-[Sum of Product Quantity] AS [Quantity on Hand]

FROM
    (
        [Product List]
        LEFT JOIN [Incoming Inventory] ON [Product List].Barcode = [Incoming Inventory].[Bar Code]
    )
    LEFT JOIN [Product Sales] ON [Product List].Barcode = [Product Sales].[Product Number]

GROUP BY
    [Product List].Barcode,
    [Product List].[Product Description],
    [Total Quantity]-[Sum of Product Quantity];

New contributor

Sophia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT