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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append Query not updating becuase of duplicates

Status
Not open for further replies.

GooGoocluster

Technical User
May 12, 2005
71
US
the table I am appending to does not allow duplicates it has a composite key (manifestID,Class,Pieces)

When I run the append query it give me the warning cannot insert duplicate key. I thought that if I clicked ok that it would work like a paste append and append what information it could. but it does not. is there somthing I can do?

Code:
INSERT INTO dbo.[New Manifest table]
                      (ManifestID, Class, Weight, Pieces, Postage)
SELECT     ManifestID, Class, Weight, Pieces, Postage
FROM         dbo.SLCManifest_Pckgs
ORDER BY ManifestID, Class
 
Are any of these fields autonumber? If so remove them from your append statement.
 
Perhaps something like this ?
INSERT INTO dbo.[New Manifest table] (ManifestID, Class, Weight, Pieces, Postage)
SELECT ManifestID, Class, Weight, Pieces, Postage
FROM dbo.SLCManifest_Pckgs S
WHERE Not Exists (SELECT * FROM dbo.[New Manifest table] WHERE ManifestID=S.ManifestID AND Class=S.Class AND Pieces=S.Pieces)

Or this:
INSERT INTO dbo.[New Manifest table] (ManifestID, Class, Weight, Pieces, Postage)
SELECT S.ManifestID, S.Class, S.Weight, S.Pieces, S.Postage
FROM dbo.SLCManifest_Pckgs S LEFT JOIN dbo.[New Manifest table] N
ON S.ManifestID=N.ManifestID AND S.Class=N.Class AND S.Pieces=N.Pieces
WHERE N.ManifestID Is Null

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
None were autonumber, PHV their is a reason why your the #1 MVP thanks again you have helped me alot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top