
June 6th, 2004, 04:44 PM
|
|
Registered User
|
|
Join Date: Jun 2004
Posts: 3
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Insert vs. Update help
Okay I'm kind of new to SQL and I have a problem.
I have the fields: name1, name2, product, and quantity
I am having trouble with insert and update because I can only run one or the other. I want to make a query that I input name1, name2, and product and if it exists already add one to the quantity and if it doesnt exist create an entry with that data and quantity = 1. So far I can only do the first.
UPDATE Order SET quantity = (quantity+1)
WHERE ((name1=input_name1) And (name2=input_name2) And (type_order=input_order));
The other would look something like this I suppose without searching for pre-existing data:
INSERT INTO Order(name1, name2, type_order, quantity)
VALUES (input_name1, input_name2, input_order, 1);
Perhaps I should make a form?
Any advice is welcome, thanks.
|