Hi,We have a management system that tracks information about different companies for various products. A specific account might consist of a number of different companies. The detail information about each company can be retrieved from the CompanyProductDetails table. If you load the below data, you will see that account '1' is associated with product 'A'. For product 'A', company '1' and '2' have various detail records. This is the problem. For an account, the product might change. If this occurs, I need to do perform two steps. first delete all the details records from AccountDetails for the old product that doesn't also exist for the new product. Second, after deleteing the old records, I need to insert into AccountDetails all the new details that don't currently exist. The main thing is the items that are incommon between products A and B must remain in the account details table. I just can't delete all the records and insert new ones (in reality, there are child tables associated with the detail so I can't loose the data).In the attached example, if switching from product A to B:Step 1for company1 delete detail 2 and 3 from AccountDetailsfor company2 delete detail 2 and 3 from AccountDetailsStep 2for company1 insert detail 4 and 5 into AccountDetailsfor company2 insert detail 5 into AccountDetailsTo make a long question short, detail 1 is shared between productA and B so must be left alone .I am stumped on how the sql queries necessary do this. any help would be appreciated.CREATE TABLE CompanyProductDetails ( [CompanyID] [varchar] (10), [Product] [varchar] (10), [DetailItem] [varchar] (10))GOCREATE TABLE AccountProducts ( [AccountID] [varchar] (10), [Product] [varchar] (10) )GOCREATE TABLE AccountDetails ( [AccountID] [varchar] (10), [CompanyID] [varchar] (10), [DetailItem] [varchar] (10))GOINSERT INTO CompanyProductDetails VALUES ('comp1','prodA','detail1') GOINSERT INTO CompanyProductDetails VALUES ('comp1','prodA','detail2') GOINSERT INTO CompanyProductDetails VALUES ('comp1','prodA','detail3') GOINSERT INTO CompanyProductDetails VALUES ('comp2','prodA','detail1') GOINSERT INTO CompanyProductDetails VALUES ('comp2','prodA','detail2') GOINSERT INTO CompanyProductDetails VALUES ('comp2','prodA','detail3') GOINSERT INTO CompanyProductDetails VALUES ('comp1','prodB','detail1') GOINSERT INTO CompanyProductDetails VALUES ('comp1','prodB','detail4') GOINSERT INTO CompanyProductDetails VALUES ('comp1','prodB','detail5') GOINSERT INTO CompanyProductDetails VALUES ('comp2','prodB','detail1') GOINSERT INTO CompanyProductDetails VALUES ('comp2','prodB','detail5') GOINSERT INTO AccountProducts VALUES('acc1','prodA') GOINSERT INTO AccountDetails VALUES ('acc1','comp1','detail1') GOINSERT INTO AccountDetails VALUES ('acc1','comp1','detail2') GOINSERT INTO AccountDetails VALUES ('acc1','comp1','detail3') GOINSERT INTO AccountDetails VALUES ('acc1','comp2','detail1') GOINSERT INTO AccountDetails VALUES ('acc1','comp2','detail2') GOINSERT INTO AccountDetails VALUES ('acc1','comp2','detail3') GO
Nic