Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help Not Inserting duplicate records

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
I would like to get some help with no inserting duplicate records into sql2000. I am using a linked server to an as400 with a vb front end. I want to use the linked server to pull data into tables that will be used in the front end app. these records will be documents that get received all day long. I will be setting up a insert query on a schedule to insert new records. but I donot want it to insert records that have already been inserted...I know I can set the field to a unique number, but then it will give an error message. is there a way to have the query check to see if the record is there and if so skip it and move to the next???

Thanks in advance
dvannoy@onyxes.com
 
This example should help you,
assume for the example that the MY_KEY is the record identifier
that is populated by whatever is in IN_DATA1.

Code:
INSERT INTO MY_TABLE
   (MY_KEY,
    MY_F1,
    MY_F2)
SELECT IN_DATA1,
    IN_DATA2,
    IN_DATA3
FROM IN_TABLE
WHERE not exists
(SELECT NULL FROM MY_TABLE WHERE
MY_TABLE.MY_KEY = IN_TABLE.IN_DATA1)

socahill@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top