SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 6th, 2004, 04:44 PM
idiotproof idiotproof is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 3 idiotproof User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old June 7th, 2004, 10:50 AM
beercraft_asp's Avatar
beercraft_asp beercraft_asp is offline
Spell Breaker
ASP Free Novice (500 - 999 posts)
 
Join Date: May 2004
Posts: 990 beercraft_asp User rank is Lance Corporal (50 - 100 Reputation Level)beercraft_asp User rank is Lance Corporal (50 - 100 Reputation Level)beercraft_asp User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 8 h 33 m 42 sec
Reputation Power: 5
Send a message via AIM to beercraft_asp Send a message via MSN to beercraft_asp
First you need Create SELECT Statement and then LOOP through records based on Query after that IF you have 0 records returened choose INSERT else UPDATE.

hope this help
Q. Are you building shopping cart???

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Insert vs. Update help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT