Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2017
  • Last Modified:

Duplicate rows in Datatable

I hava a datatable with 10 rows.  I need to duplicate those rows. How is best to do this?
(Then I will add another column to identify each row. ).
0
johnkainn
Asked:
johnkainn
1 Solution
 
Deepika_RastogiCommented:
U want to do that through code or your database query
0
 
johnkainnAuthor Commented:
I need actually to duplicate 5 times. I need also to create a new column so that each duplicate has its own number in that column, ranging from 1 to 5.
Originally I planned to do this in code, but maybe it is better to do this in SPROC. What do you think?
 Can you help me with that or should I post the question again for the sql group in this forum?
0
 
CMYScottCommented:
the SPROC would be like this...  (you'll need to add the CREATE PROCEDURE heading etc)

select * into #temp from yourtable
alter table yourtable add idx int
go
update yourtable set idx = 1
insert into yourtable select #temp.*,2 from #temp
insert into yourtable select #temp.*,3 from #temp
insert into yourtable select #temp.*,4 from #temp
insert into yourtable select #temp.*,5 from #temp
drop table #temp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now