sql server - Specifying a value and converting columns during a table transfer? -


I am currently transferring data from one database to another.

car1, car2, car3, id1, id2, id3, id4, idtxt, idtxt2

My problem is with a newly created table that contains columns in the old table:

 (ID types can be the same for multiple rows)   

In the rows, there will be a specific combination for each combination with a combination of car1, 2, 3 . id1 is always filled, while 2,3,4, textile and TCT2 can be filled or not.

My new columns include:

  car1, car2, car3, idtype, id #, text   

this new table In the idtype = id1, id2, id3, id4, id5 (idtxt), and id6 (idtxt2) while id = # for the row values ​​of the id in the table = it means that the comparison of the old table There will be more rows because there should be a line for each ID # even if they are the same combination.

How can you go about transferring this information through a stored procedure?

I can think of running only several stored procedures in the present, but it can not be answered as if I have a fixed value in addition to transferring data How to go when inserting I.e. (IDTP = ID1 for all transactions)

I am also convinced that this is not the most effective way.

Please tell me if clarification is required.

Edit, I have discovered how to insert specific values ​​during a data transfer. Other problems / suggestions are still standing.

If I correctly understand what you are doing, then you can do it together A simple query

It seems that you are trying to normalize the data, first by pivoting fields in the table and exploring them in the second.

  Select car 1, car 2, car 3, as IDT in the form of 'id1', id 1 selected from t union car 1, car 2, car All select car 1, car 2, car 3, 'id 4', id from 3, 'id2', id 2t union, select car 1, car 2, car 3, 'id3', id 3t union 4 Select All Union Car, Car 2, Car 3, 'Id2', IDText 2T from All Select Car 1, Car 2, Car 3, 'ID5', IDTex T for Union 4 & amp; nbsp;  / Pre> 

By creating a destination table and adding By coincident, or "create table as you can" or "save selected using" the other table (you are using) based on the database.

For example, if you are creating a table, your code will look something like this:

  create a table   

Comments