PDA

Click to See Complete Forum and Search --> : sql statement?


aspbeginner
Mar 21st, 2001, 01:47 PM
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)"

Active
Mar 21st, 2001, 02:22 PM
It should be Like this...

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..

Update Orders Set OFirstName='James',OLastName='Bond',OAddress1='007 Avenue',OAddress2='Bond County' Where Orders.CustomerID = 74256;

aspbeginner
Mar 21st, 2001, 02:36 PM
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?

anand
Mar 22nd, 2001, 05:47 AM
Try the select into statement