I want to return the available stock value through a query where the amount on orders is deducted from total stock and where amount on order = NULL
is transformed to 0
. So that if there are no items open on orders, it simply shows the total stock. Otherwise, it needs to deduct several items on stock.
Disclaimer: Relatively new to more advanced queries, so any explanation on what I'm doing wrong here would be incredibly helpful in the future!
Currently trying to query SQL Server, I've gotten as far that i can get most of the query to work except for the ISNULL
function
SELECT dbo.[Items].[Productcode Customer],
dbo.[Items].Description,
dbo.[Items].[Description 2],
dbo.[Items].[EAN Code],
(SELECT SUM(dbo.[Entry].[Quantity])
FROM dbo.[Entry]
WHERE dbo.[Logistic Items].No_ = dbo.[Entry].[Item SKU No_]) -
(SELECT SUM(dbo.[Order Lines].[Quantity (Base)])
FROM dbo.[Order Lines]
WHERE dbo.[Items].No_ = dbo.[Order Lines].[Item No_]
AND dbo.[Order Lines].[Document No_] LIKE '%UIT%') AS Quant_avail
FROM dbo.[Items]
LEFT JOIN dbo.[Order Lines] ON dbo.[Items].No_ = dbo.[Order Lines].[Master Item No_]
WHERE dbo.[Items].[Customer Code] = 'KL0134'
GROUP BY
"Items"."No_",
"Items"."Productcode Customer",
"Items".Description,
"Items"."Description 2",
"Items"."EAN Code"
The WHERE
function is to indicate that only outbound orders are to be deducted.
I'm getting all fields I want but the Quant_avail column is only showing NULL
. Which kinda makes sense, because there are no items on placed on orders. All i need to do now is convert the NULL
field to 0
at:
(SELECT SUM(dbo.[WMS Order Lines].[Quantity (Base)])
FROM dbo.[WMS Order Lines]
WHERE dbo.[Logistic Items].No_ = dbo.[WMS Order Lines].[Master Item No_]
AND dbo.[WMS Order Lines].[Document No_] LIKE '%UIT%') AS Quant_avail