Set Null values in query results to be equal to zero
Posted on 2006-07-19
I am trying to set up a query that gives real time reflection stock items on hand in a company warehouse.
I have a query that adds the quantity of items made to a known starting stock level and another that that counts the number of items shipped.
The query that links these two tables to provide the current stock level results in NULL values for those items that have not been shipped eg. the first line of the query result shows an item for which there are 2 in stock but because none have been shipped and the SumQtyShipped value is NULL the stock on hand is shown as NULL.
Can I force the NULL values in SumQtyShipped column to be equal to zero in order that the maths will work?
The query is below:
SELECT dbo.tblStockLevels.txtStockCode, dbo.tblStockLevels.intStartingQuantity, dbo.vwPartsIteration.TotalMade,
SUM(dbo.tblStockLevels.intStartingQuantity + dbo.vwPartsIteration.TotalMade) AS StartPlusMade, dbo.vwShippedIteration.SumQtyShipped,
SUM(dbo.tblStockLevels.intStartingQuantity + dbo.vwPartsIteration.TotalMade - dbo.vwShippedIteration.SumQtyShipped) AS QtyOnHand
FROM dbo.tblStockLevels LEFT OUTER JOIN
dbo.vwShippedIteration ON dbo.tblStockLevels.txtStockCode = dbo.vwShippedIteration.MCusSupStkCode LEFT OUTER JOIN
dbo.vwPartsIteration ON dbo.tblStockLevels.txtStockCode = dbo.vwPartsIteration.txtStockCode
GROUP BY dbo.tblStockLevels.txtStockCode, dbo.tblStockLevels.intStartingQuantity, dbo.vwPartsIteration.TotalMade, dbo.vwShippedIteration.SumQtyShipped
THank you in advance.