I am a beginner at SQL and I don't know much about Transact-SQL.
I realize this is a newbie question, but I'm looking for a simple solution.
I have a table with some columns (locationCode, CustomerCode
).
Primary table
ItemCode locationCode CustomerCode
I001 001001 C001
I002 001002 C001
I003 001001 C002
I004 002001 C002
I want to select data from this table and insert to two others table.
First table
firstTblId(autoIncrement) warehouseCode CustomerCode
1 001 C001
2 001 C002
3 002 C002
warehouseCode
is a combination of first three characters from locationCode
Data in first table are grouped by first three char of locationCode
and Customer Code
second table
secondTblId
(autoIncrement) ItemCode locationCode CustomerCode firstTblId(FK)
1 I001 001001 C001 1
2 I002 001002 C001 1
3 I003 001001 C002 2
4 I004 002001 C002 3
So, how can I insert first table and second table by selecting primary table's rows with SQL??
Thanks you for all of your replies.