Results 1 to 2 of 2

Thread: Dublicates

  1. #1
    Join Date
    Mar 2004
    Location
    Kentucky
    Posts
    19

    Unanswered: Dublicates

    can someone please explain to me how to append data to current database tables?

    If I have infromation from access and want to had the (NEW) information to current SQL tables how to I append without writing over current table information and without creating dups if the infromation currently exists within the table?

    I would like to keep the current table information and append anything new only.

    Thanks

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    A dup key in a sproc will raise by it's self to the calling sproc..

    But heres an example

    Code:
    USE Northwind
    GO
    
    CREATE TABLE myTable99(Col1 int PRIMARY KEY, Col2 char(1))
    GO
    
    DECLARE @Error int, @Col1 int, @Col2 char(1)
    
    SELECT @Col1 = 1, @Col2 = 'A'
    
    INSERT INTO myTable99(Col1,Col2) SELECT @Col1, @Col2
    
    SELECT @error = @@ERROR
    
    SELECT 'Error code: ' + CONVERT(varchar(5),@Error)
    
    SELECT @Col2 = 'B'
    
    INSERT INTO myTable99(Col1,Col2) SELECT @Col1, @Col2
    
    SELECT @error = @@ERROR
    
    IF @Error <> 0
      BEGIN
    	UPDATE myTable99 SET Col2 = @Col2 WHERE Col1 = @Col1
    	SELECT @Error = @@ERROR
      END
    
    SELECT 'Error code: ' + CONVERT(varchar(5),@Error)
    
    SELECT * FROM myTable99
    GO
    
    DROP TABLE myTable99
    GO
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •