Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Where condition (Access 2000)

    I have a code that sets a field to True wich is OK.I need however to add the condition : Where CustomerID = 118. How can i add it to the following line ?:
    strSQL = "UPDATE orders SET receipt=True WHERE orderid=(SELECT Max(orderid) FROM orders)"
    It is difficult since the code it too complicated

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Where condition (Access 2000)

    If you want multiple conditions, you combine them with AND. The keyword WHERE is used only once.

    strSQL = "UPDATE orders SET receipt=True WHERE orderid=(SELECT Max(orderid) FROM orders) AND CustomerID = 118"

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Where condition (Access 2000)

    UPDATE orders SET receipt=True WHERE orderid=(SELECT Max(orderid) FROM orders)

    This update query will update only a single record; that is, the OrderID that is the Max # in the table. Now, do you want to only update this record if it is for Customer #118, or do you want to find the Max OrderID for Customer #118 and then update that?

    The SQL statement Hans gave you will do the former. To do the latter, you'd need to do this:

    UPDATE orders SET receipt=True WHERE orderid=(SELECT Max(orderid) FROM orders WHERE CustomerID=118)
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •