Avatar of Zolf
Zolf
Flag for United Arab Emirates asked on

SQL help - Remove Null from Group By

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
Microsoft SQL ServerMicrosoft SQL Server 2008Microsoft SQL Server 2005

Avatar of undefined
Last Comment
Zolf

8/22/2022 - Mon
Farzad Akbarnejad

Hi,
add the following where caluse

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

-FA
Zolf

ASKER
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
ASKER CERTIFIED SOLUTION
Farzad Akbarnejad

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Zolf

ASKER
thanks
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck