Results 1 to 2 of 2

Thread: Update if exist, Insert If it Doesn't???

  1. #1

    Thread Starter
    Lively Member PatOls's Avatar
    Join Date
    Oct 2000
    Posts
    99

    Red face

    Hi,

    I have a problem which I hope someone will help me solve. I have a database where user places orders on ariticles. If the article already exists I want the quantity to be updated +1 or if it is a package +4. How do you find out if the article already exists in the recordset? And how do you update this article. Heres my insert into statement

    INSERT INTO tbh (Quantity, Article, Description) SELECT (Quantity, Article, Description) FROM ubh

    Now if the article that will be inserted already exists I want to be able to update it instead of creating a new line with the same article.

    thanks in advance

    //Patrick

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Location
    Bristol, UK
    Posts
    86

    Thumbs up

    You need to do a SELECT for the item first.
    Then check to see if the recordset is empty ( rs.BOF and rs.EOF)

    If its empty then use your insert statement, otherwise add the quantity to the quantity returned by your SELECT statement and update the recordset. ( rs.Update )

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