Announcement

Collapse
No announcement yet.

Problem with an SQL query

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Problem with an SQL query

    First I download all the latest orders. Then I run the following query to take all those orders (the ones in pending only) and dump them in a spreadsheet.

    However, periodically, the spreadsheet does not include all the orders. Sometimes it misses an order or two.

    Can anyone see anything wrong with the query below?

    It is supposed to select all orders in pending only...


    SELECT Person.Name, Person.ContactID, Person.[Address Line 1], Person.[Address Line 2], Person.[Address Line 3], Person.[Address Line 4], Person.[Postal Code], Person.[Address Country], Person.[Email Address], Person.[Phone Number], Order.[Order Number], OrderDetail.sProductDescription, OrderDetail.QuantityOrdered, Order.Status
    FROM ([Order] INNER JOIN Person ON Order.DeliverContactID = Person.ContactID) INNER JOIN OrderDetail ON Order.[Order Sequence Number] = OrderDetail.OrderSequenceNumber
    WHERE (((Order.Status)='N'));

    #2
    Without some testing I can't answer accurately, however at a first glance you may want to try a LEFT JOIN instead of an INNER JOIN in this SQL. This will ensure you get all the returns from the orders table.
    i.e.
    SELECT Person.Name, Person.ContactID, Person.[Address Line 1], Person.[Address Line 2], Person.[Address Line 3], Person.[Address Line 4], Person.[Postal Code], Person.[Address Country], Person.[Email Address], Person.[Phone Number], Order.[Order Number], OrderDetail.sProductDescription, OrderDetail.QuantityOrdered, Order.Status
    FROM ([Order] LEFT JOIN Person ON Order.DeliverContactID = Person.ContactID) LEFT JOIN OrderDetail ON Order.[Order Sequence Number] = OrderDetail.OrderSequenceNumber
    WHERE (((Order.Status)='N'));

    Sorry about the lazy answer. If I have more time I'll do some testing to check...
    Fergus Weir - teclan ltd
    Ecommerce Digital Marketing

    SellerDeck Responsive Web Design

    SellerDeck Hosting
    SellerDeck Digital Marketing

    Comment


      #3
      ok thanks....

      Comment

      Working...
      X