Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

migrating records to new table

$
0
0
Hi All ,

I am copying some rows from (oldCustomers) table to (newCustomers) table and I wanted to create a join table (LinkOldCustomersToNewCustomers)
that will have old customers ids and new customers ids

the oldCustomers table columns will be (ID,OrderTime,OrderDate,Location,TypeID)

the newCustomers table columns will be (ID,OrderDateTime,Location,TypeA,TypeB)


ID will be the identity of the record
OrderTime will be the time of the order
OrderDate will be the date of the order
OrderDateTime will be the order in DateTime format
Location will be a string
TypeID will be an int to specify the type of the orders
TypeA will be an int to count the number of typeA orders
TypeB will be an int to count the numberof TypeB orders


the (LinkOldCustomersToNewCustomers) table will have just (ID,oldID,NewID) 
id will be identity ,
OldID will have an id from old customers table
NewID will have the id that customer row will get after inseration in the newCustomers Table

what I want to do is to create a stored procedure to copy rows from oldCustomers to newCustomers table with a few changes
ID should be saved in the (LinkOldCustomersToNewCustomers) table
OrderTime,OrderDate should be converted to DateTime format and stored in OrderDateTime
Location should always be set to "hq"
if typeID is 1 then we add 1 to TypeA column 
if typeID is 2 then we add 1 to TypeB column

Thanks 

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>