Solved

SQL Query Help

Posted on 2014-02-18
2
212 Views
Last Modified: 2014-02-18
Hello there,

I have this sql query which is working as I expect but it is also get this null values for each product. How can I exclude those null qtyArrived and BatchNo

SELECT
        supplierOrderDetails.productID as productid,
        supplierOrder.id as supplierorderid,
        product.brandname as brandname,
        product.productcode as code,
        supplierOrderDetails.orderQty as orderQty,
        supplierOrderDetails.id as sodID,
        SUM(supplierOrderReceiveDetail.qtyArrived) as qtyArrived ,
        supplierOrderReceiveDetail.batchNo as BatchNo
    FROM
        supplierOrder  
    LEFT OUTER JOIN
        supplierOrderDetails  
            ON      (
                supplierOrderDetails.supplierOrderID = supplierOrder.ID
            )  
    LEFT OUTER JOIN
        product  
            ON  (
                product.id = supplierOrderDetails.productID
            )  
    LEFT OUTER JOIN
        supplierOrderReceive  
            ON         (
                supplierOrderReceive.supplierOrderID = supplierOrder.ID
            )  
    LEFT OUTER JOIN
        supplierOrderReceiveDetail  
            ON         (
                supplierOrderReceiveDetail.supplierOrderReceiveID = supplierOrderReceive.ID
            )           
            AND   (
                supplierOrderReceiveDetail.ProductID =supplierOrderDetails.ProductID
            )       
    WHERE
        supplierOrder.ID = 1  and supplierOrderDetails.isComplete  = 1
        GROUP BY
        supplierOrderDetails.productID,
        supplierOrderDetails.orderQty,
        product.brandname,
        product.productcode,
        supplierOrder.id,
        supplierOrderDetails.id,
        supplierOrderReceiveDetail.batchNo

Open in new window

2-18-2014-1-06-15-PM.gif
0
Comment
Question by:zolf
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39866865
change:
LEFT OUTER JOIN         supplierOrderReceiveDetail  

into
INNER JOIN         supplierOrderReceiveDetail  

to avoid non-matched rows.
however, if the columns are indeed null in that table, you need to add  this after the GROUP BY conditions:

HAVING SUM(supplierOrderReceiveDetail.qtyArrived) is not null
0
 

Author Closing Comment

by:zolf
ID: 39866967
cheers !!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

791 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