Solved

Set Null values in query results to be equal to zero

Posted on 2006-07-19
1
482 Views
Last Modified: 2008-02-26
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.
0
Comment
Question by:ReneLMadsen
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 17136716
SELECT     dbo.tblStockLevels.txtStockCode, dbo.tblStockLevels.intStartingQuantity, dbo.vwPartsIteration.TotalMade,
                      COALESCE(SUM(dbo.tblStockLevels.intStartingQuantity + dbo.vwPartsIteration.TotalMade),0) AS StartPlusMade, dbo.vwShippedIteration.SumQtyShipped,
                      COALESCE(SUM(dbo.tblStockLevels.intStartingQuantity + dbo.vwPartsIteration.TotalMade - dbo.vwShippedIteration.SumQtyShipped) ,0 )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
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
insert image with its metadata into SQL server Database 3 110
syadmin MSSQL 2 66
compare between entities in entity framework 8 72
error in my cursor 5 30
Database tuning – How to start and what to tune. This question is frequently asked by many people, both online and offline. There is no hard and fast rule-of-thumb for performance tuning, however, before beginning the tuning process one should a…
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question