MS SQL Help

Discussion in 'Databases' started by brightmosquito, Mar 26, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I have 2 tables, "Inventory" and "InventoryDetails"
    I want to display items and quantity of items. I wrote following code:

    SELECT Inventory.ID, Inventory.Name, COUNT(InventoryDetails.ID) AS Qty
    FROM Inventory INNER JOIN
    InventoryDetails ON Inventory.ID = InventoryDetails.InventoryID
    WHERE (Inventory.IsActive = '1')
    GROUP BY Inventory.ID, Inventory.Name
    ORDER BY Inventory.Name

    But if there's no record for an item in "InventoryDetails", which mean the quantity is 0, the item is not displayed.
    How can I display the quantity to be 0 ???? Please help ~~
     
  2. Try using an OUTER join instead of an inner join. Though it'll display NULL instead of 0. So you'll have to use the ISNULL function to change this to a 0.


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  3. got it. thank you.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page