Solved

SQL help - Remove Null from Group By

Posted on 2014-01-07
4
498 Views
Last Modified: 2014-01-08
Hello there,

I have this query which is working but when I do Group By it is also gets the null batchno. how can I not get those nukk batch no. see attached file to see what is happening.

cheers
Zolf

this is my query

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,
        supplierOrderReceiveDetail.expDate
    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      
    GROUP BY
        supplierOrderDetails.productID,
        supplierOrderDetails.orderQty,
        product.brandname,
        product.productcode,
        supplierOrder.id,
        supplierOrderDetails.id,
        supplierOrderReceiveDetail.batchNo,
        supplierOrderReceiveDetail.expDate

Open in new window

1-8-2014-9-14-02-AM.gif
0
Comment
Question by:zolf
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 39764341
Hi,
add the following where caluse

WHERE
        supplierOrder.ID = 1  and  supplierOrderReceiveDetail.batchNo is not null

-FA
0
 

Author Comment

by:zolf
ID: 39764351
by the way can you tell me why I get that BatchNo null even when I don't have any batch no col as null in that table
0
 
LVL 14

Accepted Solution

by:
Farzad Akbarnejad earned 500 total points
ID: 39764370
because you use outter join verb.

Change

LEFT OUTER JOIN
        supplierOrderReceiveDetail

to

INNER JOIN
        supplierOrderReceiveDetail


See
stackoverflow.com/questions/38549/difference-between-inner-and-outer-join
fro more info.

-FA
0
 

Author Closing Comment

by:zolf
ID: 39764383
thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

860 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