?
Solved

SQL help - Remove Null from Group By

Posted on 2014-01-07
4
Medium Priority
?
504 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…
Suggested Courses

741 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