Results 1 to 3 of 3

Thread: how to improve my ways of handling errors than avoiding it?

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    9

    how to improve my ways of handling errors than avoiding it?

    Let say i insert a record in my database

    New Record

    CustomerID 1111 --> Inserted Successfully

    Next record

    CustomerID 2222 --> Duplicated CustomerID --> Should show duplicated.

    Right now i am using

    IF EXISTS (SELECT ....)
    BEGIN

    INSERT
    (...)
    END

    BEGIN
    UPDATE(....)
    END
    Any ways to check for duplicated instead of updating it? Any examples?

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: how to improve my ways of handling errors than avoiding it?

    Quote Originally Posted by MSIE View Post
    Let say i insert a record in my database

    New Record

    CustomerID 1111 --> Inserted Successfully

    Next record

    CustomerID 2222 --> Duplicated CustomerID --> Should show duplicated.

    Right now i am using



    Any ways to check for duplicated instead of updating it? Any examples?
    With what you have shown it appears that CustomerID is not a primary auto incrementing field so the best method to ensure you are not inserting an exact match is to use a SELECT WHERE statement to the table to see if the CustomerID currently exists or not and from there continue with logic based on the results from the query i.e. show the current record for editing perhaps, indicate this would have been a duplicate etc.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: how to improve my ways of handling errors than avoiding it?

    Moved To Database Development

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