1

I have a table called GoodsInOld which contains 4 columns:

GoodsInOld:     Id, CustomerAccount, CustomerName, ItemId

due to a new data structure I've created 2 new tables to hold the data:

GoodsIn and GoodsInProduct.

They have a relationship like below:

GoodsIn:        Id, CustomerAccount, CustomerName ...
GoodsInProduct: Id, ItemId, GoodsInId ...

GoodsIn MAY have 1 or many GoodsInProduct

I want to insert the data from GoodsInOld into these 2 tables using a INSERT INTO or SELECT INTO?

1
  • You could always use SSIS to move the data. Then you can use a Multi cast operator to split your results to as many tables as you want. Commented Nov 21, 2013 at 16:07

1 Answer 1

2
insert into GoodsIn (CustomerAccount, CustomerName)
select CustomerAccount, CustomerName
from GoodsInOld 


insert into GoodsInProduct(ItemId, GoodsInId)
select o.ItemId, i.id
from GoodsInOld o
inner join GoodsIn i on o.CustomerAccount = i.CustomerAccount
                     and o.CustomerName = i.CustomerName
Sign up to request clarification or add additional context in comments.

1 Comment

You may also want to select distinct from GoodsInOld for your customer info to go into GoodsIn if your original table could have duplicates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.