I have an oldDB and I want to split one table of oldDB (tblCustomers) in to two tables of newDB (Customer and ReservedService) as follows:
OldDB
tblCustomers: (Code, Name, Phone, Address, Duration, Price)
NewDB
Customer: (Id, Code, Name, Phone, Address)
ReservedService: (Id, CustomerId, Duration, Price)
I have try these two queries:
query1:
use newDB
insert into newDB.dbo.Customer([Code], [Name], [Address], Phone)
select Code, SUBSTRING(Name,1,50), SUBSTRING(Address,1,100), SUBSTRING(Phone,1,50)
from oldDB.dbo.tblCustomers
query2:
use newDB
insert into newDB.dbo.ReservedService(CustomerId, Duration, Price)
select `????`, SUBSTRING(Duration,1,50), SUBSTRING(Price,1,100)
from oldDB.dbo.tblCustomers
Notice that I have two problems:
- merge these two queries in one query
- in second query the select statement should retrieve data from two tables (retrive
CusttomerIdfromnewDB.Customerand retrieve other fields fromoldDB.tblCustomers)
How can I integrate these two queries in one query without two mentioned problems?
Customer.Idcolumn in the new table an Identity column ? Also istblCustomers.Codein the old table a unique column, in simple words, You don't have One customer with multiple codes or Two different customers with the same code ? - M.Ali