Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to insert 1000 rows of data from table 1 to table 2 but table 2 have one additional column which is sequence number ( an extra column) , how can I make that column sequence . please note table 2 already have 500 records.
Posted
Updated 17-Apr-14 18:28pm
v2
Comments
Maciej Los 2-Apr-14 13:32pm    
Please, elaborate what "sequence number" means. Provide sample data and i promise to upgrade my answer.
deenasudhakar 6-Apr-14 6:42am    
Thanks for your comment.
Sequence number is like row no.
for example : An organisation have two branches in area 1 and area 2 . They maintain list of employees details in production separately now they need to merge and form single list of employees.

Solution1 is good, but i strongly recommend to define destination field list.

SQL
insert into tableB (<field_list>)
SELECT <field_list>
FROM tableA

where <field_list> is the list of fields.

Note: The data type for each field must be the same type.


More details here:
Adding Rows by Using INSERT and SELECT[^]
INSERT (sql)[^]
 
Share this answer
 
Comments
Abhinav S 2-Apr-14 13:31pm    
5.
Maciej Los 2-Apr-14 13:32pm    
Thank you, Abhinav ;)
Try
<br />
insert into tableB<br />
select col1,col2,col3,'' from tableA<br />
where '' represents value for the extra column.
 
Share this answer
 
v2
Comments
Maciej Los 2-Apr-14 13:28pm    
Good, but it needs some extra information. Please, see my comment.
deenasudhakar 6-Apr-14 6:48am    
Thanks Abhinav , but extra column is like row no. which is non identity, then it requires to fill by hand code query. pls see my comment for maciej los

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900