March 24, 2008 at 3:12 pm
I have two tables TableA and TableB
TableA
CUST_NUM, ITEM_NUM, SERIAL_NUM
TableB
CUST_NUM, ITEM_NUM, SERIAL_NUM
I need to insert data from TableB into TableA; TableB will contain some records that are already in TableA so I only want to include the records that are not currently in TableA based on ITEM_NUM, SERIAL_NUM. There will be duplicate SERIAL_NUM records in TableB but with different a ITEM_NUM which is fine. Hope I explained this adequately. Any help would be greatly appreciated.
March 24, 2008 at 3:26 pm
Is this homework? And if it is, how much help are you allowed to have from sources like this one?
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
March 24, 2008 at 3:36 pm
No this is not home work, it is a legitimate request, it may seem a simple problem to you but when one is unsure how to accomplish a particular task it is not so simple.
March 24, 2008 at 3:43 pm
INSERT INTO TableA (CUST_NUM, ITEM_NUM, SERIAL_NUM)
SELECT CUST_NUM, ITEM_NUM, SERIAL_NUM
FROM TableB
WHERE NOT EXISTS (SELECT 1
FROM TableA
WHERE TableA.ITEM_NUM = TableB.ITEM_NUM AND
TableA.SERIAL_NUM = TableB.SERIAL_NUM)
March 24, 2008 at 3:46 pm
Sorry, for the formatting. It seems no matter how I format the code this site add/strips spaces.
March 24, 2008 at 3:51 pm
No problem Adam, thanks for the help I will try it in the AM
April 2, 2008 at 11:42 am
Thanks Adam it worked like a charm.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply