Showing posts with label infromation. Show all posts
Showing posts with label infromation. Show all posts

Sunday, March 11, 2012

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.

ThanksA dup key in a sproc will raise by it's self to the calling sproc..

But heres an example

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