Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2014
  • 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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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