Results 1 to 4 of 4

Thread: sql statement?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Posts
    18

    Unhappy

    I am using this sql statement and it does not put any values into the orders table. Any ideas?

    strq = "INSERT INTO Orders(OFirstName, OLastName, OAddress1, OAddress2) " _
    & "SELECT Customers.FirstName, Customers.LastName, Customers.Address1, Customers.Address2 " _
    & "FROM Customers, Orders WHERE Customers.CustomerID=Orders.CustomerID"

    I was using the sql statement and I got the error message:
    Syntax error. in query expression 'Select Customers.FirstName'

    strq = "Insert Into Orders(OFirstName, OLastName, OAddress1, oAddress2) Values " &_
    "(Select Customers.FirstName,Customers.LastName, Customers.Address1, Customers.Address2 " &_
    "from Customers, Orders WHERE Customers.CustomerID=Orders.CustomerID)"

  2. #2
    Addicted Member Active's Avatar
    Join Date
    Jan 2001
    Location
    Lat: 13° 4' 46" N, Long: 80° 15' 20" E
    Posts
    209
    It should be Like this...

    Code:
    Insert into Orders(OFirstName, OLastName, OAddress1,OAddress2) Values ('James','Bond','007 Avenue','Bond county');
    An Insert Statement is used for Adding a New Record..
    You cannnot use it to Update a Record.

    To Update a Record..

    Code:
    Update Orders Set OFirstName='James',OLastName='Bond',OAddress1='007 Avenue',OAddress2='Bond County' Where Orders.CustomerID = 74256;
    If you can't beat your computer at chess, try kickboxing !!!
    [Download Tag Editing Tools.]

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Posts
    18
    Thank you for your reply.

    I have two tables: customers and orders

    customers table:

    customerid
    firstname
    lastname
    address1
    address2
    city
    state
    zip
    country
    email
    phone
    fax


    orders:
    orderid
    customerid
    odate
    oamount
    ofirstname
    olastname
    oaddress1
    oaddress2
    ocity
    ostate
    ozip
    ...
    ...
    ...

    I use a join between the customers and orders table and I get the sql statement from Microsoft Access 2000:

    SELECT
    FROM Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID;


    I have customer information in my customer table and want to copy firstname, lastname, address1, address2,
    city, state, etc to orders table. How do I do that?

  4. #4
    Member
    Join Date
    Apr 1999
    Location
    Hyderabad,AndraPradesh,India
    Posts
    59
    Try the select into statement

Posting Permissions

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



Click Here to Expand Forum to Full Width